1

I have developed one application with deployment target and ios sdk as 6.0. Later my client demanded the app should run in ios 5.0+ devices.So i have changed deployment target to 5.0 and disabled autolayout property of IB as mentioned here in stack, but now iam getting the error as shown below:

> -[UIBarButtonItem setBackgroundImage:forState:style:barMetrics:]: unrecognized selector sent to instance 0x2971f0

And i didn't find anything wrong with my UIBarButtonItem,

 addButton = [[UIBarButtonItem alloc]
        initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
        target:self
        action:@selector(addProject)];

now iam struggling to find a solution, waiting for your valuable help.. thanks in advance.

Community
  • 1
  • 1
Mumthezir VP
  • 6,251
  • 6
  • 28
  • 57
  • 1
    That method is only available in iOS 6.0+ – Elliott Mar 16 '13 at 09:29
  • 1
    i haven't used any method like that.. this is what i have in my code:- addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addProject)]; – Mumthezir VP Mar 16 '13 at 09:31
  • Its Available in iOS 5.0 and later. – Shamsudheen TK Mar 16 '13 at 09:32
  • @ElliottPerry you should write that as an answer because it's correct. He needs to do respondstoselector and have the two versions of the add button. – badweasel Mar 16 '13 at 09:34
  • Should make a custom button and add it to bar button using initWithCustomView – Kasaname Mar 16 '13 at 09:50
  • 1
    @mvp You're correct, there should be nothing wrong with that line of code. The problem must be elsewhere. Could you humor me and search your codebase for the `setBackgroundImage:forState:style:barMetrics:` method (obviously don't search for that entire line of text because it will be broken up by parameter names and types. **Try searching for "barMetrics"**). – Elliott Mar 16 '13 at 10:04

1 Answers1

2

setBackgroundImage:forState:barMetrics: is available in iOS 5.0+ but setBackgroundImage:forState:style:barMetrics: is only available in iOS 6.0+

Shamsudheen TK
  • 30,739
  • 9
  • 69
  • 102
  • 2
    `setBackgroundImage:forState:barMetrics:` is available in iOS **5.0+** but `setBackgroundImage:forState:style:barMetrics:` is only available in iOS **6.0+**. – Elliott Mar 16 '13 at 09:51
  • do an if responds to selector to pick which one, not based on the OS version. that's the right way to know which one to use. – badweasel Mar 16 '13 at 10:07