Iphone 在UIBarButtonItem setTintColor上发送了无法识别的选择器
我在应用商店中有一个应用,我正在使用Flurry analytics。我经常会遇到一个无法处理的异常错误 NSInvalidArgumentException:-[UIBarButtonim setTintColor:]:发送到实例0x177b20的选择器无法识别 消息:应用程序崩溃 我搞不懂的是,我没有在任何地方设置任何工具栏按钮项目的颜色。我有一些自定义视图,其中设置了右栏按钮项,但没有色调 我对这个按钮的大多数用法都是这样的Iphone 在UIBarButtonItem setTintColor上发送了无法识别的选择器,iphone,ios,uibarbuttonitem,unrecognized-selector,Iphone,Ios,Uibarbuttonitem,Unrecognized Selector,我在应用商店中有一个应用,我正在使用Flurry analytics。我经常会遇到一个无法处理的异常错误 NSInvalidArgumentException:-[UIBarButtonim setTintColor:]:发送到实例0x177b20的选择器无法识别 消息:应用程序崩溃 我搞不懂的是,我没有在任何地方设置任何工具栏按钮项目的颜色。我有一些自定义视图,其中设置了右栏按钮项,但没有色调 我对这个按钮的大多数用法都是这样的 - (void)viewDidLoad { [super
- (void)viewDidLoad
{
[super viewDidLoad];
UINavigationBar *bar = [self.navigationController navigationBar];
[bar setTintColor:[UIColor colorWithRed:0 green:69.0/255 blue:118.0/255 alpha:1]];
self.navigationItem.title = @"Edit User";
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc]
initWithTitle:@"Save"
style:UIBarButtonItemStylePlain
target:self
action:@selector(editUser:)];
self.navigationItem.rightBarButtonItem = saveButton;
[saveButton release];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:@selector(cancel)];
[[self navigationItem] setLeftBarButtonItem:cancelButton];
[cancelButton release];
}
如果有人对这个问题有任何见解,我将不胜感激。我的项目目标是iOS 4.0及以上版本
更新:
我发现是什么导致了setTintColor上的一些随机问题。我发现我正在为一个实际的工具栏按钮项目设置色调颜色。我猜操作系统版本之间存在一些可能导致崩溃的差异。因此,如果有人能告诉我一种与操作系统无关的方法来设置我的导航栏中的自定义右栏按钮项目,我将不胜感激。您是否尝试过:
self.navigationController.navigationBar.tintColor =[UIColor colorWithRed:0 green:69.0/255 blue:118.0/255 alpha:1];
?如果您的目标是iOS 4.0,则可以执行以下操作: 在您的AppDelegate.m中,在@end之后的末尾输入以下代码:
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
UIColor *color = [UIColor YOUR_COLOR];
self.tintColor = color;
//if you want image for background use this code
UIImage *img = [UIImage imageNamed: @"IMAGE_NAME.png"];
[img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
希望这有帮助。对我来说,这是工作。问题在于在两个类上错误地使用setTintColor-setTintColor在4.x设备上不受支持,因此当较旧的设备遇到该颜色时,您将崩溃。听起来更像是一个注释而不是答案。否。我似乎无法在模拟器或设备上复制该问题。我会试试这个,让你们知道。我最近和你们的关系有些问题。有时,您只需在NavigationController的子视图上调用setTintColor。([[[self.navigationController.navigationBar子视图]objectAtIndex:1]setTintColor:[UIColor redColor]];)至少这为我解决了这个问题。我还发现,IOS 5.0及以下版本不支持
MPVolumeView
的TintColor
。