Unrecognized selector sent to UIBarButtonItem setTintColor

I have an app in the app store where I use Flurry analytics. And from time to time I get an unhandled exception error that I cannot understand.

NSInvalidArgumentException: - [UIBarButtonItem setTintColor:]: unrecognized selector sent to instance 0x177b20 Msg: application is broken

What I can not understand, I do not install anywhere at any time. I have several custom views in which I set the right panel button element, but there are no shades.

Most of my button buttons 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 understands this problem, I will be very grateful. I am targeting iOS 4.0 and in my project.

UPDATE: I figured out what causes some random issues in setTintColor. I found that I was setting the hue color on one of the panel elements. I assume that there are some differences between OS versions that can lead to crashes. Therefore, if someone can tell me a neutral OS way to set a custom right-hand button in my navigation bar, this will be appreciated.

+6
source share
3 answers

The problem was the misuse of -setTintColor on 2 classes. -setTintColor is not supported on 4.x devices, so you will crash when older devices are in shade color.

+7
source

You tried:

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

?

+3
source

if your goal is iOS 4.0, you can do this: In your AppDelegate.m, at the end after @end, enter 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 

I hope for this help. It works for me.

+1
source

Source: https://habr.com/ru/post/903979/


All Articles