UITableView issue when using separate delegate/dataSource

I followed your steps, recreated the project and ran into the same problem. Basically you are almost there. There are 2 things missing (once fixed it works):

  • You need to connect the tableView of the TableTestTableViewController to the UITableView you have on the screen. As I said before because it is not IBOutlet you can override the tableView property and make it and IBOutlet:

    @interface TableTestTableViewController : UITableViewController {
        UITableView *tableView;
    @property (nonatomic, retain) IBOutlet UITableView *tableView;
  • Next thing is to add a reference to the TableTestTableViewController and retain it in the TableTestViewController. Otherwise your TableTestTableViewController may be released (after loading the nib with nothing hanging on to it.) and that is why you are seeing the erratic results, crashes or nothing showing. To do that add:

    @interface TableTestViewController : UIViewController {
        TableTestTableViewController *tableViewController;
    @property (nonatomic, retain) IBOutlet TableTestTableViewController  *tableViewController;

    and connect that in the Interface Builder to the TableTestTableViewController instance.

With the above this worked fine on my machine.

Also I think it would be good to state the motivation behind all this (instead of just using the UITableViewController with its own UITableView). In my case it was to use other views that just the UITableView on the same screenful of content. So I can add other UILabels or UIImages under UIView and show the UITableView under them or above them.

Leave a Comment