UITableViewCell content flickers while reloading cells individually

前端 未结 5 1200
余生分开走
余生分开走 2021-02-08 13:25

I have a table view linked to a NSFetchedResultController (i.e. loading data and also tracking changes to data is bound to the FRC)

I\'m not using Auto

5条回答
  •  广开言路
    2021-02-08 13:56

    If anyone encountered the same problem:

    If you are calculating your cell height and its elements and you are dependent on NSIndexPath for querying any data or conditions, always check that your index path is valid (not nil). Most of UITableView methods that return index path (e.g -(NSIndexPath *)indexPathForCell:.., etc.) may return nil values and will shoot you down an spiral that is debugging views.

    In my case, I had a method to determined if my cell should have a header, and for that I checked wether it is the first cell or a condition has changed since previous cell. the problem was indexPath.row == 0 is true even if the index path is actually nil (it's a conceptual problem in Objective-C where nil is 0). so for a brief moment my cells would thought it has a header!

    I feel kind of stupid not checking for nil index paths but I think sharing it might help somebody someday.

提交回复
热议问题