iOS UIBarButtonItem action

jvpython

macrumors 6502
Original poster
Aug 25, 2011
284
0
New Zealand
I've been having an issue in an app that I've developed under Xcode 4.5 DP4 where nothing happens when the user taps a Bar Button Item linked to an Action. I have tried several method for doing this such as linking the Bar Button Item inside a toolbar to an IBAction and also doing this programatically like this:

Code:
theButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonItemStyleBordered target: s:confused:elf action: @selector(theButtonPressed:)];
But none of these seem to work as nothing happens when the button is pressed. I never had this issue in previous versions of iOS. Does anyone have any idea what the problem is here? Thanks
 

Reason077

macrumors 68020
Aug 14, 2007
2,193
685
Code:
theButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonItemStyleBordered target: s:confused:elf action: @selector(theButtonPressed:)];
How did you declare theButtonPressed? If its declared like

Code:
-(void)theButtonPressed {...}
then you need to use
Code:
@selector(theButtonPressed)
not:
Code:
@selector(theButtonPressed:)
 

Duncan C

macrumors 6502a
Jan 21, 2008
853
0
Northern Virginia
I've been having an issue in an app that I've developed under Xcode 4.5 DP4 where nothing happens when the user taps a Bar Button Item linked to an Action. I have tried several method for doing this such as linking the Bar Button Item inside a toolbar to an IBAction and also doing this programatically like this:

Code:
theButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonItemStyleBordered target: s:confused:elf action: @selector(theButtonPressed:)];
But none of these seem to work as nothing happens when the button is pressed. I never had this issue in previous versions of iOS. Does anyone have any idea what the problem is here? Thanks
The code you posted does not make sense. "...target: s:confused:elf action:..." The syntax for method calls should be

[object methodname: param1
paramName2: paramvalue2
paramName3: paramValue3...
<paraNameX: paramValueX>]

You should have matched pairs of key:value entries. If you have a:b:c, something is wrong.
 

jvpython

macrumors 6502
Original poster
Aug 25, 2011
284
0
New Zealand
The code you posted does not make sense. "...target: s:confused:elf action:..." The syntax for method calls should be

[object methodname: param1
paramName2: paramvalue2
paramName3: paramValue3...
<paraNameX: paramValueX>]

You should have matched pairs of key:value entries. If you have a:b:c, something is wrong.
The ":confused:" part just appeared when I copy pasted and posted the code. It was supposed to be there ;)
 

jvpython

macrumors 6502
Original poster
Aug 25, 2011
284
0
New Zealand
How did you declare theButtonPressed? If its declared like

Code:
-(void)theButtonPressed {...}
then you need to use
Code:
@selector(theButtonPressed)
not:
Code:
@selector(theButtonPressed:)
Thanks for the info, but I just checked the code and it's fine. The strangest thing is that when I simply link the button to an IBAction from Interface Builder it actually works in the simulator but on my iPhone...