I am working on an iPhone application that has a fairly large UITableView with data taken from the Internet, so I am trying to optimize its creation and use.
I found out that dequeueReusableCellWithIdentifier is very useful, but after looking at many source codes using this, I am wondering if the use I use for this function is good.
Here's what people usually do:
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"Cell"];
And here is how I did it:
// The cell row NSString identifier = [NSString stringWithFormat:@"Cell %d", indexPath.row]; UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (cell != nil) return cell; cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:identifier]; // Add elements to the cell return cell;
The difference is that people use the same identifier for each cell, so excluding one of them avoids adding a new one.
For me, the task of the queue was to provide each cell with a unique identifier, therefore, when the application asks that the cell is already displayed, neither selection nor addition of elements is required.
In thin, I donโt know which is better, the โgeneralโ method allows you to use the table memory for the exact number of cells that it displays, but the method I use, apparently, it stores all the calculated cells, but can cause a large amount of memory ( if there is no internal limit for the queue).
Am I using it this way? Or does it depend only on the developers, depending on his needs?
optimization objective-c iphone uitableview
Jukurrpa May 28 '10 at 12:21 2010-05-28 12:21
source share