Avoiding the crash with dataSource and a custom UITableViewDataSource (for your UITableView)

If you implement the UITableViewDataSource protocol in a class (that isn't a UITableViewController) and set the dataSource outlet in of your UITableView to an instance of that class, your app will crash.

After a bunch of fruitless searching, finding that other people were having the same problem but nobody was posting the solution, I found it myself.

The solution is *NOT* calling setDataSource: from awakeFromNib in your UITableViewDataSource class, that won't work.

The solution is calling [self.tableView setDataSource:dataSource] from the viewDidLoad method in your UITableViewController class. That means you'll need an outlet in your UITableViewController to your UITableViewDataSource, but that's easy to add.

Written on April 23, 2009