我已经看到您可以为UITabBarItem添加selectedImage以及图像,因此我修改了Cordova插件以添加该图像:
UIImage *tabIcon = [UIImage imageNamed:imageName];
UIImage *selectedTabIcon = [UIImage imageNamed:selectedImage];
tabIcon = [tabIcon imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
selectedTabIcon = [selectedTabIcon imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item = [[UITabBarItem alloc] initWithTitle:title image:tabIcon tag:tag selectedImage:selectedTabIcon];
其中selectedImage变量是插件在此处传递的字符串:
NSString *name = [arguments objectAtIndex:0];
NSString *title = [arguments objectAtIndex:1];
NSString *imageName = [arguments objectAtIndex:2];
NSString *selectedImage = [arguments objectAtIndex:3];
int tag = [[arguments objectAtIndex:3] intValue];
但是,当我尝试对此进行编译时,出现以下错误:
/Users/tomchambers/work/cordova-ios-tab-bar/src/ios/CDVTabBar.m:266:34:
错误:没有可见的@interface
对于'UITabBarItem'声明选择器'initWithTitle:image:tag:selectedImage:'
item = [[UITabBarItem alloc] initWithTitle:title图片:tabIcon标签:tag selectedImage:sel ...
~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
产生1个错误。
** BUILD FAILED **
我没有使用目标C的经验,所以我认为这可能是我在这里缺少的简单事情。
当使用其他方法时(肯定存在图像):
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"random" image:[UIImage imageNamed:@"www/assets/images/tab-bar-icons/ic_mail_outline.png"] selectedImage:[UIImage imageNamed:@"www/assets/images/tab-bar-icons/ic_mail_outline.png"]];
2016-02-08 11:48:31.367 Movidiam[1847:843403] Apache Cordova native platform version 3.9.2 is starting.
2016-02-08 11:48:31.369 Movidiam[1847:843403] Multi-tasking -> Device: YES, App: YES
2016-02-08 11:48:31.372 Movidiam[1847:843403] Unlimited access to network resources
2016-02-08 11:48:31.679 Movidiam[1847:843403] [CDVTimer][statusbar] 152.289033ms
2016-02-08 11:48:31.680 Movidiam[1847:843403] [CDVTimer][TotalPluginStartup] 152.797997ms
2016-02-08 11:48:31.847 Movidiam[1847:843403] Resetting plugins due to page load.
2016-02-08 11:48:34.294 Movidiam[1847:843403] -[__NSDictionaryM intValue]: unrecognized selector sent to instance 0x13f82d430
2016-02-08 11:48:34.295 Movidiam[1847:843403] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM intValue]: unrecognized selector sent to instance 0x13f82d430'
*** First throw call stack:
(0x1834f9900 0x182b67f80 0x18350061c 0x1834fd5b8 0x18340168c 0x1000eaf4c 0x100102528 0x100101df4 0x183ebbe20 0x1834b0efc 0x1834b0990 0x1834ae690 0x1833dd680 0x1848ec088 0x188254d90 0x1000c7814 0x182f7e8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
最佳答案
用于实例化TabBarItem的方法不存在。您必须使用以下任何一种:
UITabBarItem * item = [[UITabBarItem alloc] initWithTitle:@"title" image:[UIImage imageNamed:@"image.png"] tag:1];
要么
UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:@"title" image:[UIImage imageNamed:@"image.png"] selectedImage:[UIImage imageNamed:@"selectedImage.png"]];
关于ios - 尝试设置selectedImage时,UITabBarItem没有可见的界面,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35267719/