views:

31

answers:

3

Hi all,

I have so many cells in table view say nearly 500. Each and every cells have their own images and string paragraphs. Actually i draw those images & strings with the help of UIView's drawRect method. So i need to calculate image and each string's position (including their width & height to measure the cell height and wrapping areas). If i did the calculation at a time for all cells, it takes some time.. Thats not good. I want to show the cells quickly. So i want to do calculations only for the visible cells and want to immediately show the visible cells. Then the calculation for other cells should happend in the background. One more thing, i will do calculations only once for each cell. Once i did, i will store the values in array. Next time i will simply show the things according with the array values, not by calculations..

Please anyone help me to do it... I just want to know whether it is possible? if yes, what is the procedure to achieve it?

Thanks in Advance...

+2  A: 

There is no "procedure" to do this. UITableView always behaves this way. You provide callbacks to tell it how many sections and rows-per-section there are, and how to populate each cell. The UITableView will only ask you to populate cells that are visible, and will even recycle cells when they scroll off the edge (as opposed to just creating them ad infinitum).

Marcelo Cantos
A: 

You can retrieve the visible cells in UITableViewController via

[self.tableView indexPathsForVisibleRows]

then you can do the processing for the visible cells. e.g.

for (NSIndexPath *path in paths ) {
// do some processing in [self.tableView cellForRowAtIndexPath:path]
}

I did the same custom view for 1000+ rows with custom drawrect for each cell and used the method above in order to optimize loading of cells. My processing only takes place during the ff:

  1. On load (viewDidLoad), update visible cells.

  2. When user stops scrolling (default to a blank place holder when scrolling)

Manny
A: 

I think you could use the visibleCells property of UITableView.

UITableView *tableView;
NSArray *cells = tableView.visibleCells;
Jongsma