Understanding Reload, Repaint, and Re-Layout for UITableView

Leaning the Objective-C language isn’t that bad; the true hurdle in learning to develop for iPhone is in understanding the frameworks. UITableView and UITableViewController is a perfect example of how a developer, new to iPhone, can get lost in a quagmire of documentation. Most recently I found my self looking for a way to tell a UITableView that its model had changed and that it needed to refresh itself. This began a journey of discovery that has helped me better understand the UITableView APIs.

Repaint and Re-layout

The first step is to understand the various concepts related to updating UIViews. Repaint and Re-Layout are concepts that are available at the UIView level and manifest themselves as follows:

[myView setNeedsDisplay]; // repaint
[myView setNeedsLayout]; // re-layout

NOTE A call to setNeedsLayout will only have an effect if your UIView overrides the layoutSubviews method. This would be the case if you had a UITableViewCell that had multiple subviews that you manually layout.

In most cases, I find that it is sufficient to call setNeedsDisplay. A good example of this is when a UIImageView is rendered with one image; and while it is still on screen, you change the image to something else. In this case, just changing the image will not always trigger a repaint of the view, for that to occur you need to make a call to setNeedsDisplay.

Reloading Data

Reloading data is different from a repaint as it usually implies that the underlying data model has changed. This was the case I found myself in most recently when I was trying to refresh the contents of a table that was displaying a list of feeds from Jaiku. In this scenario trying to tell every table cell to reload or repaint would have been pointless as the model they were operating against was no longer valid.

UITableView has a method designed specifically for this scenario and it usage looks like this:

[myTableView reloadData];

NOTE: This approach will usually result in the recreation of all new table cell instances. If this is something you feel strongly about, you may want to look into the batch updating features of a table. For more information, take a look at the following methods in UITableView:

- (void)beginUpdates;
- (void)endUpdates;
- (void)insertSections:(NSIndexSet *)sections withRowAnimation: (UITableViewRowAnimation)animation;
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation: (UITableViewRowAnimation)animation;
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation: (UITableViewRowAnimation)animation;
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation: (UITableViewRowAnimation)animation;


  1. reloadData was exactly what I was looking for. when my table view showed the second time (after the data model had changed) the visible cells were still showing the old data while new cells (after scrolling) would show the new data. Thanks!

  2. Should [myTableView reloadData] work if you are using Reusable UITableViewCells with the reuseIdentifer? It doesn’t appear to “flush” the cells that have been queued for reuse.

    If I don’t use that, then it works fine.

  3. reloadData was also exactly what I needed. I kept trying to get loadData to also repaint. Much easier this way. Thanks

  4. So, you only call [view reloadData] if you’ve changed the dataSource?

    If you haven’t changed the dataSource, but the dataSource has new data, will [view setNeedsDisplay] be sufficient?

  5. Just wanted to say thanks for this.

    I spent a little too long for comfort thinking about how to force a table to clear itself from the cache and reload itself (effectively recalling all those UITableViewDelegate methods I had implemented) when I wanted it to display a changed data set.


    Best wishes.

  6. What would cause this?

    I have a grouped tableView that I’ve added in IB. 2 groups. 3 rows in each group.

    It displays fine when my app is first run. (So I know I’m doing SOMETHING right. Wouldn’t that mean that I (at least) have my Delegate, DataSource, IBOutlets, and connections set up correctly?)

    But when I click on a button that calls [myTable reloadData] it just crashes.

    Initially, I thought it was due to my changes in the number of groups, number of rows, or changing the data in my dataSource (just a small NSMutableArray).

    But the same thing happens when I change NO data: Works fine the first time my tableView is displayed. But crashes when I call [myTable reloadData]. (Whether the data has changed or not.)

  7. I notice I can separately reload a “section”, a “row”, or the entire table.

    What if I just need to update the headers or footers?

  8. I find if I call reload data after I have entered the detail of a cell that I don’t return back to the table view, but stay in the detail Any ideas on haw to make it show thte list view again?

  9. ReloadData is great but it doesn’t have animation delete or insertSections.

  10. ReloadData was exactly what I was looking for. Thanks!!!
    When the user clicked on one cell, I changed the accesory to show a checkmarck, but it didn’t appeared unless I scrolled the complete list of elements, on this moment, it appeared the checkmark.
    I’ve been 2 hours looking for the problem and reading the classes documentation. Thanks for helping us.

  11. Thanks for the tip. Found out if within the UITableViewController, you can use [self.tableView reloadData];

  12. Many thanks for the tip.

    My data didn’t change, i needed only to refresh my UITableView : [myTableView reloadData] did it perfectly !

Comments are closed.