Become a MacRumors Supporter for $25/year with no ads, private forums, and more!

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,486
1,242
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:)
 
Comment

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.
 
Comment

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 ;)
 
Comment

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...
 
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.