Search code examples
iosobjective-cuitableviewredrawnsfetchedresultscontroller

How to update table view cell?


I have a UITableView with one big cell and many small cells. When I receive content from server I update my UITableView with function - (BOOL)performFetch:(NSError **)error (NSFetchedResultsController). I noticed that my big cell has dublicate after update and the second cell doesn't reload. When I scroll down and scroll to top table looks good. How can I solve my problem?

enter image description here


Solution

  • "performFetch" updates the datasource but the tableview itself is not updated.

    For updating the tableview use either

    - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths
                  withRowAnimation:(UITableViewRowAnimation)animation
    

    or

    - (void)reloadSections:(NSIndexSet *)sections
          withRowAnimation:(UITableViewRowAnimation)animation
    

    You can pick the animation you like best, for example UITableViewRowAnimationMiddle or just UITableViewRowAnimationAutomatic

    For performance reasons update only as much as necessary.