UITableView Best Practices

What are the best practices for working with UITableViews to increase productivity, speed up development and maintenance when working with UITableViews?

+6
source share
2 answers

This is not the first time this question has been asked on SO. Here is my previous answer on this:

  • Dynamic row height is expensive because it cannot cache processed views efficiently since the runtime does not know what height you are going to return for a given cell until it makes a call. Do not use it if at all possible. I was told by Apple Engineers that it’s more efficient to draw all the cells a little higher than necessary to allow for a few large lines than using dynamic height.
  • Only select an array element once [items objectAtIndex:indexPath.row] in the -tableView:cellForRowAtIndexPath:
  • Use the cache for any images or other network resources. Try the EGOImageView stack , it caches the image efficiently and is pretty pretty code.
  • While you are in the gigub EGO code, grab them with EGOCache and use it to cache any other objects that you need to manipulate, such as strings that are parsed and modified.
  • If any of your views on this cell is transparent, watch the WWDC 2011 video on UIKit performance. They have a more efficient method. for transparency of table cells.
  • If you are using basic data, use NSFetchedResultsController in the table view. It handles loading errors, caching indexes, and other performance indicators specific to ivews tables.

Also watch the video at WWDC using tools, they tell you how to find where the drawing code kills performance. This year there were some (some, not all) really wonderful sessions.

+5
source

Optimize the latter, so the UITableViewCell subclass if you need custom cells - and if you ever want to improve rendering performance, you might want to display the content using drawRect: instead.

+1
source

Source: https://habr.com/ru/post/891385/


All Articles