UITableView: cellForRowAtIndexPath Call continues

I have a UITableView Controller and a UITableView. Everything is set up for me with the help of delegates, etc., and it fills perfectly. I noticed a small error, but with the following method:

: cellForRowAtIndexPath

I notice that this method is constantly being called every time I look at the table. Even after the table is full, it continues to ring. Basically, a cell goes out of sight, when it returns to sight, it calls it up again. My NSLog has printed the contents of the cell inside this method, and I know that it continues to call.

If this function does not just call once per cell to fill it, then do?

+6
objective-c xcode uitableview ios4
source share
2 answers

Nope. This is called every time a cell is needed, and a cell is needed every time it is displayed.

UITableView is a very smart little thing. It literally only stores the cells that it displays, plus the cache is literally two or three. When the time comes to scroll the cell, which was not there, you can request a cell from the cache, and if it is, it will be reused.

Thus, HUGE data sets can be displayed in a UITableView, because in reality there are not a large number of cells in the memory, only those on the screen and a small cache.

+8
source share

This is the correct behavior. This is due to the removal of UITableViewCells. This is why cell reuse is important. Thus, ideally, there is a finite small amount built into memory that is constantly reused.

Refer to the docs for more information and sample code.

0
source share

All Articles