I need two UITableViews in the same NIB. I have used IB and created a view with the two tables.
My header file contains the ViewController and two classes, one for each of the tables (see below). In IB I can connect each table’s delegate and datasource to FileOwner, but I cannot work out how to create the IBOutlet connection. I’m getting this message: -[News tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x15d3c0
2011-12-11 07:20:27.480 myCity1[659:707] Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[News tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x15d3c0’
Here’s the header file:
@interface News : UIViewController {
}
@end
@interface TownNews : UITableViewController {
UITableView *townNewsTable;
}
@property (nonatomic, retain) IBOutlet UITableView *townNewsTable;
@end
@interface GeneralNews : UITableViewController {
UITableView *generalNewsTable;
}
@property (nonatomic, retain) IBOutlet UITableView *generalNewsTable;
@end
I was dealing with this thing in one of my projects (you can watch it: free app with name IJCAI11 in the appstore; the tab ‘People’ (there the indexing is done with a separate tableView)); and as far as I see by the code above, you’re making things to be too complicated. I’ll describe how I did it instead of saying what you shouldn’t do 🙂
I had only one class, let’s say YaddaYaddaViewController.
Note that the viewController is derived from UIViewController, not UITableViewController (the goal of class UITableViewController is to be able to implement simple tableView in 2 minutes, for more custom stuff you should always use UIViewController. To read more about that, take a glance at the documentation of UITableViewController class).
In the IB for “File’s Owner” I simply set YaddaYaddaViewController;
I link the tableView1 and tableView2 outlets to the proper tables in the View;
I link the delegate and the datasource to the both tableView1/2, so I have ‘multiple’ delegate and datasource.
And finally, in the code, for all delegate methods (e.g. tableView:cellForRowAtIndexPath:)
I just pay attention to the tableView value, a delegate-event of which caused the calling of this method, like:
Hope this helps!