Unrecognized selector sent on UIBarButtonItem setTintColor
Asked Answered
J

3

6

I have an app in the app store that I'm using Flurry analytics on. And I keep getting an unhandled exception error from time to time that I can't figure out.

NSInvalidArgumentException: -[UIBarButtonItem setTintColor:]: unrecognized selector sent to instance 0x177b20 Msg: Application crashed

What I can't figure out is, I'm not setting any bar button items tint color anywhere. I have a few custom views where I am setting the right bar button item, but no tint.

Most of my uses of the button look like this.

- (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];

}

If anyone has any insight into this issue, I would be very grateful. I am targeting iOS 4.0 and up in my project.

UPDATE: I figured out what was causing some of the random issues on the setTintColor. I found that I was setting the tint color on one of the actual bar button items. I'm guessing there are some differences between OS versions that can cause crashes. So if anyone can tell me an OS neutral way of setting a custom right bar button item in my navigation bar, it would be appreciated.

Jeanette answered 17/12, 2011 at 14:52 Comment(1)
I've had some problems with the recently. Sometimes, you have to just call setTintColor on the NavigationController's subviews. ([[[self.navigationController.navigationBar subviews] objectAtIndex:1]setTintColor:[UIColor redColor]];) At least that fixed it for me.Flasher
J
7

The problem was with errant -setTintColor usage on 2 classes. -setTintColor is not supported on 4.x devices, so you will crash when older devices bump into the tint color.

Jeanette answered 22/12, 2011 at 15:7 Comment(1)
I also found that TintColor is not supported on IOS 5.0 and below for a MPVolumeView.Sanorasans
I
3

Have you tried :

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

?

Impious answered 17/12, 2011 at 15:4 Comment(2)
Sounds more like a comment than an answer.Christan
No. I can't seem to replicate the issue in the simulator or on my device. I'll try this out and let you know.Jeanette
P
1

if your target is iOS 4.0 you can do this: In your AppDelegate.m in the end after @end put this code:

@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

Hope this help. For me it's work.

Plasmasol answered 17/12, 2011 at 16:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.