Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView Best Practices [closed]

What are the best practices when dealing with UITableViews in order to improve the performance, speed up the development and maintenance when dealing with UITableViews?

like image 835
atiq Avatar asked Jun 26 '11 11:06

atiq


People also ask

Why is there extra padding at the top of my UITableView?

Short answer is that this extra padding is probably due to the table view header (not the section header), and that UITableView doesn't like to be assigned a header with a height of 0.0.

What is the difference between UICollectionView and UITableView?

For the listing details of each item, people use UITableView because it shows more info on each item. The UICollectionView class manages an ordered collection of data items and presents them using customizable layouts.

How can I improve my TableView performance?

Cache can basically solve most performance problems. TableView needs to know the height of the Cell to layout the Cell. You need to know the height of all the Cells to know the height of the TableView itself. Therefore, every time you call reloadData, you need to calculate the height of all the Cells.

What is true about Uiviewtable section?

UITableView manages the basic appearance of the table, but your app provides the cells ( UITableViewCell objects) that display the actual content. The standard cell configurations display a simple combination of text and images, but you can define custom cells that display any content you want.


2 Answers

This isn't the first time this question has been asked on SO. Here's my previous answer on the matter:

  • Dynamic row height is expensive, because it cannot cache the rendered views efficiently, as the runtime doesn't know what height you're going to return for a given cell until it makes the call. Don't use it if at all possible. I was told by Apple Engineers that it's more efficient to draw all the cells a little taller than necessary to account for a few larger rows, than to use dynamic height.
  • Only fetch the array item once [items objectAtIndex:indexPath.row] in the -tableView:cellForRowAtIndexPath: method
  • Use a cache for any images or other network resources. Try the EGOImageView stack, it caches it's image efficiently, and is some pretty slick code.
  • While you're in the EGO github code, grab their EGOCache and use it to cache any other objects you need to manipulate, such as strings that are parsed and modified
  • If any of your views on that cell are transparent, watch the WWDC 2011 video on UIKit performance. They have a much more efficient method to draw transparency on tableview cells
  • If you're using Core Data, use the NSFetchedResultsController in your table view. It handles loading faults, caching indexes, and other efficiencies specific to table ivews.

Also watch the WWDC video on using instruments, they go over how to find where drawing code is killing performance. This year had some (some, not all) really great sessions.

like image 97
RyanR Avatar answered Oct 15 '22 03:10

RyanR


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

like image 38
Piotr Avatar answered Oct 15 '22 04:10

Piotr