1
votes

I am trying to customize the navigation bar and it's buttons in my AppDelegate file :

// first I am customizing the done button

    [[UIBarButtonItem appearance] setBackgroundImage:buttonDone forState:UIControlStateNormal style:UIBarButtonItemStyleDone barMetrics:UIBarMetricsDefault];
    [[UIBarButtonItem appearance] setBackgroundImage:buttonDonePressed forState:UIControlStateHighlighted style:UIBarButtonItemStyleDone barMetrics:UIBarMetricsDefault];


//and then I am customizing the back button


    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBackPressed forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];

I am getting [_UIBarItemAppearance setBackgroundImage:]: unrecognized selector sent to instance for the done button. The weird thing is that the customisation for the back button works while the one for the done button crashes the app. Any ideas why?

*PSbuttonDone, buttonDonePressed, buttonBack and buttonBackPressed are four UIImage-s that I created*

UPDATE : on iOS 5.0 simulator the app crashes but on 6.0 it works. Any suggestions on what could I do to avoid the crash on 5.0 ?

1
what ios version are you developing on ?giorashc
You realize you are using a different method for the back button right?borrrden
...and what iOS version are you running on?Phillip Mills
on iOS 6 it works, it crashes on iOS 5, any suggestions on what could I do to avoid the crash?Teo

1 Answers

1
votes

From the docs this signature is available only from iOS 6.0+

You can test an object method availability by :

[obj respondsToSelector:@selector(<methodName>)]

So try :

id item = [UIBarButtonItem appearance];
if ([item respondsToSelector:@selector(setBackgroundImage:forState:style:barMetrics:)]) {
   // Use new signature
 } else {
   // Use old signature
 }