I've created an application using the Navigation-based template in Xcode. I've also created a class that implements the UITableViewDataSource protocol and would like to use it for that UITableView in the RootViewController.
I've tried setting the dataSource property in viewDidLoad, and in all flavors of initializers, but I can't get it to work.
How can I do this?
Currently I'm doing the following:
- (void)viewDidLoad {
[super viewDidLoad];
// The Navigation Controller uses this to display the title in the nav bar.
self.title = @"Names";
// Little button with the + sign on the right in the nav bar
self.navigationItem.rightBarButtonItem =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showAddNameScreen)];
// Set the data source and reload.
[self.tableView setDataSource:[DataAcceess sharedInstance]];
[self.tableView reloadData];
}
But the table just stays empty and the data source methods never get called (numberOfRowsInSection
and cellForRowAtIndexPath
)
Edit: My sharedInstance
was buggy and returning nil. No methods were ever called on it.