App crashes when an outlet is set

Discussion in 'iOS Development' started by unbekannt1234, Jul 11, 2010.

  1. unbekannt1234

    unbekannt1234 New Member

    Joined:
    Dec 11, 2008
    Messages:
    13
    Likes Received:
    0
    Device:
    2G iPod touch
    Hello everybody,

    I'm making my first steps in iPhone developing and I'm facing a problem at present.

    When I set an outlet to an arbitrary control, for example to a label or a button, and switch to the according view with my TabBarController, the application crashes.

    Within the ViewController.h file I declared
    in the @interface section and
    and used the @synthesize statement in the .m file.

    When I do the same procedure with a button and set an action instead of an outlet, the view is loaded fine but the app crashes when I press the button.

    To be sure that I'm able to set an outlet correctly, I quickly created an app with a simple label which gets its text changed at startup - everything is working.

    Is there anything special about setting outlets while using a TabBarController?

    Thanks in advance.
  2. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    I assume this means that sent the button the –[addTarget:action:forControlEvents:] message? When the app crashes, what does gdb say? My guess is than an unrecognized selector exception is thrown...in that case, are you sure that the target param responds to a method specified by the selector param? Though I do not have enough information to speak definitively, it's very likely that you have successfully set a target and selector for a certain event, but when that event happens/is handled, the button is being sent a message to which it cannot respond (method does not exist or has not been implemented). GCC would give you a warning for the latter.
  3. unbekannt1234

    unbekannt1234 New Member

    Joined:
    Dec 11, 2008
    Messages:
    13
    Likes Received:
    0
    Device:
    2G iPod touch
    Thanks for your answer.

    When I press the button and the app crashes, the debugger says:
    Having set an outlet to the button and the app crashes while switching to the according view, gdb tells me:
    I attached the view so you have the chanche to look inside the code (although there isn't really much of it) and see if something is wrong.

    Thanks again

    Attached Files:

  4. SpeedyApocalypse

    SpeedyApocalypse Member

    Joined:
    Dec 27, 2009
    Messages:
    564
    Likes Received:
    13
    Device:
    4G iPod touch
    I think I got it working for you. I just renamed the IBAction and put it before all of your properties. You don't need to create a UIButton as an IBOutlet if you just want to execute an IBAction. You only need the button as an IBOutlet if you are going to manipulate the button.

    If all your button did is create a UIAlertView, I removed the (id)sender and just put it as:

    -(IBAction)yourButton;

    Try it out and tell me if it works for you

    Please Register or Log in to view images

    Attached Files:

  5. unbekannt1234

    unbekannt1234 New Member

    Joined:
    Dec 11, 2008
    Messages:
    13
    Likes Received:
    0
    Device:
    2G iPod touch
    Thanks again for your answer, SpeedyApocalypse, but it didn't solve my problem, but...

    After spending a lot more time into investigating the problem, I figured out that the problem was caused by the fact that I forgot / didn't knew that I had to set the Class of the TabBar items to the according ViewController.

    Now, everything works fine and I can finally start coding. It's unbelievable how happy I am now

    Please Register or Log in to view images

    )
  6. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch
    IBAction is just void.
  7. SpeedyApocalypse

    SpeedyApocalypse Member

    Joined:
    Dec 27, 2009
    Messages:
    564
    Likes Received:
    13
    Device:
    4G iPod touch
    I put it like that in the .h file, it was -(IBAction)action { } in the .m.
  8. lauNchD

    lauNchD Well-Known Member

    Joined:
    Jan 27, 2008
    Messages:
    1,844
    Likes Received:
    261
    Device:
    iPhone 5 (Black)
    SpeedyApocalypse meant to strip the sender argument IN the IBAction. Nevertheless, I don't see how that would solve anything.

    BTW: I know IBAction is just void, and IBOutlet is just an empty #define, but they're still necessary for Interface Builder to recognize them.

Share This Page