How to debug a problem with an unrecognized selector sent to an instance?

I have the following code in a view controller, which (in all other respects) seems to work fine:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { ProblemViewController *problemViewController = [[ProblemViewController alloc] initWithNibName:@"ProblemViewController" bundle:nil]; problemViewController.problem = (Problem*)[self.problems objectAtIndex:indexPath.row]; [self.navigationController pushViewController:problemViewController]; [problemViewController release]; } 

However, when I run this function, I get the following error:

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[ProblemViewController initWithNibName:bundle:]: unrecognized selector sent to instance 0x57ca80' 

I don’t understand what could be causing this, so my question is: what is the best way to debug this problem? Is there something obvious that I should check?

+6
iphone
source share
5 answers

Check the base class for the ProblemViewController. I am sure that you are not inheriting from the UIViewController, which includes the initWithNibName:bundle: method.

+6
source share

There are a bunch of answers to this question that everyone basically says the same thing, right, the thing: somehow the method that you are trying to call does not actually exist.

BUT, if you hit your head against a wall (for example, I have been for an hour today), first try to clear the project in xcode. Sometimes I don’t know why, xcode can get into a bad state and will not compile your project correctly into a simulator. He will tell you that the assembly was successful, but when deployed on the simulator, you begin to see errors at runtime, as if only half of your changes were matched. So yes, this is happening.

+5
source share

This method is probably not implemented in your task manager. An unknown selector, as far as I know, simply there is no method defined in this class interface that has this signature.

Try declaring it in your interface as follows:

 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil; 
+2
source share

I thought it was better to write something on this. I fought with him for a couple of days. There are a lot of blogs about this, but none of them solved the problem. Some have suggested that this is due to the pushViewController, which should indicate animated: YES. This worked for some, but it did not help solve the problem. I used the button to access another view, and not to select a row from the table view, but I got the same unrecognized selector error. I also used a navigation controller, so I thought this was due to this, but it is not. Finally, I decided to comment on the lines of code until the message disappeared. After commenting on the method that caused the problem, the error message still appeared in the console. It was then that I realized that the problem was not with my source code. One site recommended cleaning and rebuilding. I tried all this and the problem continued. Then I looked at my XIB file using Interface Builder to find out which methods (received actions) are displayed on File Owner. There was a problem. Not only the violation method was displayed once on the file owner, but it was displayed twice. Don't know how to display image of this here. Anyway, I deleted the (Received Actions) methods with the same name that appeared in File Owner. I did a cleanup and a remake to see if the error cleared, and that happened. Then I split the source, which I thought was bad, and again built the project, and the challenge of the new submission was successful.

+1
source share

I will share my experience with the same error code. You can make a mistake by assigning the object to the wrong target. For example, if you have some kind of UILabel property and you accidentally set the string constant directly to self.myUILabelProperty = @ "ups", then the property will become an object of type NSString instead of UILabel, so you will lose all UILabel methods. After this error, if you try to use the UIlabel methods for a property in the code, you will receive this error message.

+1
source share

All Articles