![]() | unrecognized selector sent to instance |
|
09 Dec 2008, 22:46
Craig Williams (6 posts) |
I am not sure what I am missing here. I went through the videos once and everything worked correctly. I started over to go through them a second time and I can’t get past the first part. I have started from scratch five times and reinstalled Xcode just for good measure. Each time I get the same error:
Here is my .m file code:
and here is the .h file:
Thanks for any help. Craig |
|
10 Dec 2008, 12:17
Bill Dudney (917 posts) |
Check what the datasource for you tableview is set to. Everything in your code looks fine so my guess is that the datasource is set to a different object. Good luck! |
|
10 Dec 2008, 15:19
Craig Williams (6 posts) |
Thanks for following up Bill. So others may benefit from my mistake, here was the issue. |
|
10 Dec 2008, 16:10
Bill Dudney (917 posts) |
Hi Craig, So you had your table view’s datasource connected to the files owner in the MainWindow.xib file? And the file’s owner is the UIApplicaiton which does not conform to the UITableViewDatasource protocol. Thanks for following up! |
|
09 Feb 2009, 10:19
Danish Najam (6 posts) |
Hi Bill, I bought all your episodes. And they were really helpful in giving me Ramp up over iPhone Application Development. And by progressing through those I have got a slightly different version of the above problem. I am creating Tab Bar Application using the template and in that I have attached the nib files in each of the Tab Bar item. Then Each of the view has been shown successfully. Now I want to loads a table view in each of the tabs. I have created separate View Controller (VC) for each of the Tab and mentioned those VC name in each nib file’s File owner class attribute. My View Controller declaration is below and I have implemented the required method in FirstViewController.m similar to below - (UITableViewCell )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@”myCel”];
if(nil == cell) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@”myCel”] autorelease];
}
cell.text = @”test”;
return cell; - (NSInteger)tableView:(UITableView *)tv numberOfRowsInSection:(NSInteger)section {
return 1; - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@”cell clicked {%d, %d}}”, indexPath.row, indexPath.section);
Now I request you to please help me about what I missed or went wrong in it. |
|
09 Feb 2009, 10:38
Danish Najam (6 posts) |
Sorry Bill for bothering you. However it ended up being a connection problem in IB. I didn’t have each tab connected to a view controller. I only had them connected to the xib files. Lemme add a word for naive user like me that do connect your Tab Bar in the Main window xib to your custom view Controllers as well. |
|
09 Feb 2009, 12:27
Bill Dudney (917 posts) |
Hi Danish, No problem at all, questions that get answered all by themselves are the easiest :) Let us know when you get an app published! |
|
26 May 2009, 20:34
Anthony Palomba (2 posts) |
Hey Bill, I am trying to get through episode 1 and have encountered the same I followed the tutorial but when I build and run the app in the emulator, 2009-05-26 15:19:09.354 Recipes[3138:20b] cellForRowAtIndexPath: {0}} I downloaded the example source and confirmed that it matches mine. Thanks, |
|
26 May 2009, 20:59
Bill Dudney (917 posts) |
Its just a typo in your code, The method name you are sending is ‘initWithFrame:resuseIndentifier:’ and the proper method name is ‘initWithFrame:reuseIdentifier:’. You should have a warning from the compiler that ‘initWithFrame:reuseIndentifier:’ might not be implemented ( a yellow line in the code). Hope this helps. |
|
26 May 2009, 21:04
Anthony Palomba (2 posts) |
Gah! Yes that was indeed the problem. Sorry to bother you for such a thing, |
|
27 May 2009, 02:12
Bill Dudney (917 posts) |
No worries, happens to me all the time. |
|
03 Jun 2009, 08:02
Giannandrea Castaldi (1 post) |
Hi, The solution should be in the message posted by Danish: ”... it ended up being a connection problem in IB. I didn’t have each tab connected to a view controller. I only had them connected to the xib files. Lemme add a word for naive user like me that do connect your Tab Bar in the Main window xib to your custom view Controllers as well …”. Giannandrea |
|
03 Jun 2009, 10:31
Bill Dudney (917 posts) |
The error message says that an instance of ‘UIViewController’ was sent the message ‘tableView:numberOfRowsInSection:’. That method is part of the table view data source protocol. So my guess is you have a connection from a table view to a ‘File’s Owner’ object that has had its class set to your particular view controller. But the real instance, created in another nib file, has not had its class set. Check each nib file to make sure all the view controllers have their class set properly. Good luck. |
|
06 Aug 2009, 17:22
Jeremy W. (20 posts) |
Hi, just wanted to contribute, I was a little confused. I have the same tab based app that Danish Najam has along with the same error, so I ended up here :) To make this easier, I will explain my app a little. I have a tab bar, it contains 3 icons (contact, activities & history). I created my application using the xcode template for tab app. Like it suggested I created a separate “MainView” for my contacts so each “entitiy” has it own view.XIB. I then created classes for each controler ie. ContactViewControler. The part that I was confused on was apparently you have to specify the class (ContactViewControler) in two places Once I did this all my error went away, luck I had no code issues. I say all of this to ask, why do we have to specify the controler class twice. more specifically why does the tab bar care, should the NIB file we load take care of all of that and the tab bar is merely a short cut or link to the ContactsView? Just looking for some clarification, and logical reasoning. |
|
07 Aug 2009, 18:53
Bill Dudney (917 posts) |
Hi Jeremy, The ‘File’s Owner’ is not an object, its a proxy. The real object lives in the other nib file. There is where you must set the class. You can leave ‘File’s Owner’s class as NSObject if you want and it would still load. However, the view outlet must be set on a view controller. For the files’ owner to know that it has a view you must set the class to something deeper in the hierarchy than NSObject (namely at least UIViewController). If you want IB to know about your specific outlets then of course you must tell it the file’s owner is of your class. Another source of info on the files owner is the documentation on the ADC site in the discussion of nib files. Good luck, and I hope this helps. |
|
29 Aug 2009, 01:55
Andrew Hall (2 posts) |
Hi Bill, I’m trying to draw various polygon shapes in a UIView. + (NSArray )pointsForPolygonInRect:(CGRect)rect numberOfSides:(int)numberOfSides; and in my PolygonShapeView.m file, in my – (void)drawRect:(CGRect)rect method, I message above method as follows: NSArray *points = [self pointsForPolygonInRect:[self frame] numberOfSides:numberOfSides]; When I do, I get the following logged to the debugger console: and I get my yellow warning in Xcode. I can’t see that i’ve got typos in the method call. I’ve tried to follow the IB discussions above. My PolygonShapeView view is connected to my controller as a Referencing Outlet, my File’s Owner class is UIApplication with a class outlet to my system defined delegate. I can’t seem to get a handle on what’s wrong with the selector and why it isn’t recognized. My Xcode warning is that my PolygonShapeView class object may not respond to ‘-pointsForPolygonInRect:numberOfSides:’ Any time and help is much appreciated. |
|
01 Sep 2009, 10:54
Bill Dudney (917 posts) |
Hi Andrew, Sorry to be late to respond. It looks to me like you are sending a class method (the + at the front of the method is what makes it a class method) to an instance. Instead of [self pointsForPolygonInRect:numberOfSides:] you have to send this message to the class with [[self class] pointsForPolygonInRect:numberOfSides:]. Or you can make that method an instance method (but that seems wrong given the name of the method). Hope this helps! |
|
06 Sep 2009, 02:59
Andrew Hall (2 posts) |
Bill, Thanks again! |
|
07 Feb 2011, 03:33
David Whitehurst (4 posts) |
I am receiving the following error and I’m finding that many things can cause this error. I think it’s something in IB. I’m not really sure. Here’s the console output:
My method is here in RootViewController: - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// select static row and view controller
Punch *obj = [self.punchList punchAtIndex:indexPath.row];
NSLog(
My design is as follows: I started with an iPad split-view template and then I replaced the RootViewController popOver with a UINavigationController. I also created a separate RootViewController.xib file with a TableView. I select “Projects” and then bomb with the above error. I was loading the RootViewController’s view with Objects.name in the cells. I simplified this table with strings in an NSArray. I thought that the Punch object in the View (e.g. punch.name) was really not a String. The NSLog works and I see the String selected. I’m really stumped. Thanks for any help folks. |
|
07 Feb 2011, 05:13
David Whitehurst (4 posts) |
I solved my problem partially. I solved the problem where I select from the RootViewController view and now my SecondLevelController is placed on the stack and instantiated. The problem is that I used data from the iPhone SDK book where “key” is used for DVDCabinetController. I want to use this setup so that I can pull from the database a list of “Projects”,”Applications”, and “Products” from the root view. I commented out all the array and dictionary stuff and the selector issue went away. It was because “key” is not recognized or set I don’t think. Not sure:
And the projectController code:
The fixed array works but use of “key” gives the selector error. I haven’t brought in the data model yet so that’s why I’m just looking for good design. I like the concept of calling the projectController maybe SecondaryViewController and switching on “key” or similar. Can anyone explain why I get a selector error? Thanks in advance, David |
| You must be logged in to comment |

