【问题标题】:Unrecognized selector sent on UIBarButtonItem setTintColor在 UIBarButtonItem setTintColor 上发送的无法识别的选择器
【发布时间】:2011-12-17 14:52:03
【问题描述】:

我在应用商店中有一个正在使用 Flurry 分析的应用。而且我时常会收到一个我无法弄清楚的未处理异常错误。

NSInvalidArgumentException: -[UIBarButtonItem setTintColor:]: 无法识别的选择器发送到实例 0x177b20 消息:应用程序崩溃

我想不通的是,我没有在任何地方设置任何条形按钮项目的着色颜色。我有一些自定义视图,我正在设置右侧栏按钮项,但没有色调。

我对按钮的大部分使用都是这样的。

- (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 上的一些随机问题。我发现我正在为一个实际的条形按钮项目设置色调颜色。我猜操作系统版本之间存在一些可能导致崩溃的差异。因此,如果有人能告诉我在我的导航栏中设置自定义右栏按钮项的操作系统中立方式,将不胜感激。

【问题讨论】:

  • 我最近遇到了一些问题。有时,您只需要在 NavigationController 的子视图上调用 setTintColor。 ([[[self.navigationController.navigationBar subviews] objectAtIndex:1]setTintColor:[UIColor redColor]];) 至少这对我来说是固定的。

标签: iphone ios uibarbuttonitem unrecognized-selector


【解决方案1】:

问题在于 2 个类的错误 -setTintColor 使用。 -setTintColor 在 4.x 设备上不支持,所以当旧设备碰到 tint 颜色时你会崩溃。

【讨论】:

  • 我还发现TintColor 不支持MPVolumeView 的 IOS 5.0 及以下版本。
【解决方案2】:

你试过了吗:

self.navigationController.navigationBar.tintColor =[UIColor colorWithRed:0 green:69.0/255 blue:118.0/255 alpha:1];

?

【讨论】:

  • 听起来更像是评论而不是答案。
  • 没有。我似乎无法在模拟器或我的设备上复制该问题。我会试试这个并告诉你。
【解决方案3】:

如果您的目标是 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

希望对您有所帮助。对我来说,这是工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多