views:

809

answers:

3

HI guys,

I have this error that is keeping me from moving forward. I basically have an application which contains a UITabViewController which points to individual UIViewControllers. So one of the tabs, I want to implement a basic TableViewController.

Now, no matter what i do, whether its cut and paste sample UIViewController code that implements a UITableView, or whatever, or even just the default UITableViewController template from Xcode, i get the same error below:

2009-09-06 12:29:23.889 iKosher[12536:207] * -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xe1d8d0 2009-09-06 12:29:23.891 iKosher[12536:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xe1d8d0' 2009-09-06 12:29:23.891 iKosher[12536:207] Stack: ( 807902715, 2492915529, 808284155, ...

In IB, all I have done is drag onto the view a UITableView and set its delegates to point to the file owner.

Not sure what else i can do from here

A: 

It looks like your code is sending a tableView:numberOfRowsInSection: message to a UIViewController instance. I think it should be sending that message to an object that implements the UITableViewDataSource protocol.

Check your implementation file for the UITableViewController you are using to make sure it has the tableView:numberOfRowsInSection: method implemented (or uncommented, depending on how you generated the file).

If you have any code, post it.

Rob Jones
hey mate, well its not a UITableViewController im implementing but UIViewController that has the two delegate methods for UITable (UITableViewDataSource) etc. the method numberofrows is already in there, and IB's file owner seems to be pointing to this instance.
Doron Katz
So, you want to implement your own version of UITableViewController? That's how I understand what you've said. Have you tried skinnying this back to just making the Table portion work, without all the complexity of Tabs?
Rob Jones
Hi Rob I have tried both ways. I tried having a UITableViewController (just used default template from XCode for UITableViewC) and it still has the same error. I have tons of sample code on this ive taken from other places and they still provide the same error. Therefore its not hte code but either IB or the underlying tabs. But the latter shouldnt be the problem because i have other controllers that work fine with it, and this is my second controller.
Doron Katz
+2  A: 

Make sure that the File's Owner object in IB is set to be an instance of the UITableViewController subclass that you're implementing, and that it has a tableView outlet that's linked to your table view.

Tim
But the instance controller I have is a UIViewController which implements UITable delegate and datasource. The IB's File owner is pointing to that UIViewController instance.
Doron Katz
Why don't you change it to a UITableViewController instance?
Rob Jones
@Rob Jones is right. Your life will get a lot easier if you make it a UITableViewController. However, my first point still stands (sort of) - make sure the File's Owner object in IB is set to be an instance of the class you're implementing, not just UIViewController.
Tim
Thanks Tim but I have removed the controller and added a UITableViewController from Xcode with all the default implementation of delegates and still the same. I dont understand why this has to be difficult and different.
Doron Katz
Can you confirm for me that all your IB outlets (including `view`, `tableView`, and `delegate`) are set properly, and that your File's Owner object is an instance of your class? That's the most common reason to get the problem you're seeing, and nothing you've said so far has confirmed that for me.
Tim
Hi Tim, this is totally frustrating. OK, Ill list what ive done step by step.Ive deleted the new controller and now I just have the tab controller (root) that maps to individual uiviewcontrollers. The first one is just a controller with some text (works fine).Now, the table goes in the second one so i recreate a new UITableViewController which adds in its template all the required delegate stuff. The code seems fine, as all the delegate methods are implemented.Now to IB:Created new View NIB,dragged tableview to view.Renamed File Owner to the xcode's controller i created. continued...
Doron Katz
Then, I dragged from file owner to main view to get the outlet. Then i dragged the two delegate links from the ui table view back to the file owner. Thats all there is right? Unless im missing something. SO yeah, build and boom, the same error again. Not sure, maybe i should send you my code or something. I cant post it on the comments here, unless i create a new question.
Doron Katz
Hi Tim, I have ported the code for this controller into a new temporary project and it works fine. So there must be some hierarchical issue with my UITabViewController root and this? I use IB to map the TabView Controller to point to individual UIViewControllers for each screen.
Doron Katz
Hi Tim. I got it working! OK guys, this is something for newbies to remember. When you have a UITabViewController pointing to individual UIViewControllers through IB, make sure you set the actual button to point to the UIViewController, as well as pressing command+4 to set the class to that same UIViewController. I forgot the latter, so you have to set it twice. Sorry Tim, I feel like a dumbo, but thanks mate.
Doron Katz
A: 

I ran into this problem, the key was changing class identity in Interface Builder.

sunkencity