I have a simple cell – designed in IB – and with the reuseIdentifier set. Below code works quite nicely. HOWever – the NSLog() reveals that the results are never cached.
Table view controller class:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
switch/case for various cell types
{
Foo * item = [results objectAtIndex:indexPath.row];
return [MyCell tableView:tableView populatedCellWith:item];
}
}
MyCell class..
+(UITableViewCell *)tableView:(UITableView *)tableView populatedCellWith:(Foo *)item
{
static NSString * identifier = @"XXX";
MyCell *cell = (MyCell *) [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
NSArray * items = [[NSBundle mainBundle] loadNibNamed:@"MyCell"
owner:self options:nil];
cell = [items objectAtIndex:0];
assert( cell && [cell.reuseIdentifier isEqualToString:identifier]);
NSLog(@"That was a load - rather than a nice cache for %@", self.class);
}
fill out some stuff.
return cell;
}
Why is this – as it makes things a lot more efficient ?
Thanks,
Dw.
The way you create the table view cell can not make sure to put the cell into the reusable queue in table view. Only way to do that is to use
My another question