1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Unrecognized selector sent to instance ERROR using UITabBarController

Discussion in 'iPhone/iPad Programming' started by roeik, Dec 29, 2008.

  1. macrumors member


    I need help desperately. I keep getting the following error:

    2008-12-29 21:28:23.609 TabApplication[7510:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIViewController printSomething]: unrecognized selector sent to instance 0x529c80'

    I basically created a UIButton and connected an action to it -- nothing too fancy. But I keep getting this error. I think it has something to do with the UITabBarController. Everything works well on the MainWindow.xib, but this error is generated on another .xib file which is loaded by the second UITabItem. I used the built-in Tab Bar application when I created the project.

    Any suggestions? Please. I lost two days on this error.
  2. Moderator


    Staff Member

    Can you show us how printSomething is defined and how you are calling it?
  3. macrumors member

    The interface:

    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>

    @interface UpdateController : NSObject {

    -(IBAction) printSomething;


    in the implementation file I have this function:

    -(IBAction) printSomething {

    I don't call the function specifically from anywhere. I connected the Touch up inside event to printSomething using the connection inspector in interface builder.

    Thank you for trying to help.

  4. Moderator


    Staff Member

    I believe IBActions are sent a 'sender' parameter when hooked up via IB. Therefore, try this instead:
    @interface UpdateController : NSObject {
    -(IBAction) printSomething:(id)sender;
    and then:
    -(IBAction) printSomething:(id)sender {
  5. macrumors member

    I tried this before. I keep getting the same error:

    2008-12-30 03:13:11.100 TabApplication[8883:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIImageView printSomething]: unrecognized selector sent to instance 0x59f6a0'

    any other ideas?
  6. Moderator


    Staff Member

    Hmm, you really want your UpdateController to be a subclass of NSObject and not UIViewController?

    And I'm just reaching for straws at this point. Not really sure what the issue is without seeing more of the code and the .xib file, which is kinda hard for you to pass on.
  7. macrumors member

    well, I tried both ways. it doesn't help.
  8. macrumors member


    So I isolated the problem and I am definitely doing something wrong using the built-in tab controller.

    To facilitate the process and for order to you to see exactly what happens I detailed the steps I have taking (when creating a new tab bar application) that results the error I am getting.

    This is what I do: in xCode I started a new project --> new Tab Bar Application.

    I double-clicked the secondView.xib that was created. I dragged a button from the library to the view. I also dragged another Object and named the class controller (subclassing NSObject). I created a new action using Interface Builder called printSomething. Then I chose file-->write class files and in the printSomething function just put an NSLog. Using the connection inspector, I connected the Touch Up Inside event of the button to printsomething in the controller. If you follow all these steps (they take two minutes), you will get an error when clicking the button. What am I doing wrong?

    Thank you for your help.

  9. Moderator


    Staff Member

    I'm kinda unclear what you're doing in this part and what purpose it's meant to accomplish. Can you elaborate?
  10. macrumors member

    I am creating another file in the .xib bundle where I write my functions(Actions) and connect them to the UIControls in the view.
  11. macrumors member

    Let me phrase my question differently. After creating a new Tab Bar application, who will y ou go about creating a button on the second screen does something (i.e. print an NSLog comment)?
  12. Moderator


    Staff Member

  13. Moderator


    Staff Member

    I'm beginning to think that starting with the Tab Bar Application template is more of a hindrance than a help. I've had luck adding a second ViewController subclass but can't seem to get the event for the button hooked to any IBAction.

    So, I'm gonna suggest that you might be better off starting off with less in your initial project. Here's another tutorial that follows that mindset a little closer: Tab Bar Controller Tutorial

Share This Page