PDA

View Full Version : Unrecognized selector sent to instance ERROR using UITabBarController




roeik
Dec 29, 2008, 02:36 PM
Hi,

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.
Thanks.
Roei.



dejo
Dec 29, 2008, 02:41 PM
Can you show us how printSomething is defined and how you are calling it?

roeik
Dec 29, 2008, 03:13 PM
The interface:

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

@interface UpdateController : NSObject {
}

-(IBAction) printSomething;

@end

in the implementation file I have this function:

-(IBAction) printSomething {
NSLog(@"Roei");
}

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.

Roei

dejo
Dec 29, 2008, 03:48 PM
I believe IBActions are sent a 'sender' parameter when hooked up via IB. Therefore, try this instead:
@interface UpdateController : NSObject {
}

-(IBAction) printSomething:(id)sender;

@end


and then:
-(IBAction) printSomething:(id)sender {
NSLog(@"Roei");
}

roeik
Dec 29, 2008, 07:16 PM
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?

dejo
Dec 29, 2008, 07:48 PM
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.

roeik
Dec 30, 2008, 08:24 AM
well, I tried both ways. it doesn't help.

roeik
Dec 30, 2008, 01:24 PM
Hey,

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.

Roei

dejo
Dec 30, 2008, 05:45 PM
I also dragged another Object and named the class controller (subclassing NSObject). I created a new action using Interface Builder called printSomething.
I'm kinda unclear what you're doing in this part and what purpose it's meant to accomplish. Can you elaborate?

roeik
Dec 30, 2008, 06:11 PM
I am creating another file in the .xib bundle where I write my functions(Actions) and connect them to the UIControls in the view.

roeik
Dec 30, 2008, 08:20 PM
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)?

dejo
Dec 30, 2008, 10:13 PM
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)?
I'm working on what I would do.

In the mean time, maybe this tutorial can give you some direction, although it doesn't demonstrate your exact requirement:
http://icodeblog.com/2008/10/13/iphone-programming-tutorial-using-tabbarview-to-switch-between-views/

dejo
Dec 31, 2008, 12:06 PM
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 (http://www.iphonesdkarticles.com/2008/07/tab-bar-controller-tutorial.html)