UIBarButtonItem action

Discussion in 'iOS Programming' started by jvpython, Aug 17, 2012.

  1. macrumors 6502

    Joined:
    Aug 25, 2011
    Location:
    New Zealand
    #1
    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
     
  2. macrumors 68000

    Reason077

    Joined:
    Aug 14, 2007
    #2
    How did you declare theButtonPressed? If its declared like

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

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #3
    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.
     
  4. thread starter macrumors 6502

    Joined:
    Aug 25, 2011
    Location:
    New Zealand
    #4
    The ":confused:" part just appeared when I copy pasted and posted the code. It was supposed to be there ;)
     
  5. thread starter macrumors 6502

    Joined:
    Aug 25, 2011
    Location:
    New Zealand
    #5
    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...
     

Share This Page