6

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

4

3 回答 3

7

问题在于 2 个类的错误 -setTintColor 使用。-setTintColor 在 4.x 设备上不受支持,因此当旧设备遇到色调颜色时,您会崩溃。

于 2011-12-22T15:07:24.377 回答
3

你有没有尝试过 :

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

?

于 2011-12-17T15:04:41.407 回答
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

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

于 2011-12-17T16:21:19.853 回答