UITableView Custom Cells Disappearing content after Scrolling

In my case, what was happening was that I had not kept a strong pointer to the tableview's dataSource. So when the tableview was scrolled, the datasource had already been freed and set to nil, which led to the tableview getting 0 for numRowsForSection and nils for cellForRowAtIndexPath.

If anyone has a similar problem, you might look if your datasource and/or custom objects are retained properly.


Are you adding the UITableViewcontroller as addSubView ? Then you should do like this :

1) addChildViewController,then
2) addSubview
The problem is delegate and datasource of the tableview getting nil since the parent controller unable to a reference to the UITableViewController.

In my case the problem was the following:

  1. I had a special case where view controller's view was not pushed or presented modally but I've added it as a subview (view.addSubview) to another view.

  2. This way the actual view was retained by its superview, but ViewController object (which was DataSource for table view) was not retained and went out of memory.

  3. I had to assign view controller to a (strong) variable so it stayed in memory.