PDA

View Full Version : UIBarButtonItem action




jvpython
Aug 17, 2012, 11:12 PM
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:

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
Aug 18, 2012, 04:04 AM
theButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonItemStyleBordered target: s:confused:elf action: @selector(theButtonPressed:)];


How did you declare theButtonPressed? If its declared like

-(void)theButtonPressed {...}

then you need to use @selector(theButtonPressed) not: @selector(theButtonPressed:)

Duncan C
Aug 18, 2012, 11:20 AM
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:

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
Aug 18, 2012, 06:29 PM
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
Aug 18, 2012, 10:52 PM
How did you declare theButtonPressed? If its declared like

-(void)theButtonPressed {...}

then you need to use @selector(theButtonPressed) not: @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...