我有一个简单的单元格 - 在IB中设计并使用reuseIdentifier集合。下面的代码很好地工作。无论如何 - NSLog()显示结果永远不会被缓存。dequeueReusableCellWithIdentifier:标识符没有选择一个loadNibNamed单元格
表视图控制器类:
- (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类..
+(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;
}
这是为什么 - 因为它使事情变得更有效率?
谢谢,
Dw。
所以,你所看到的NSLog的不止一次?试图澄清你的问题。 – 2010-12-16 19:11:38
是的确 - 它们已经设置了一个单元格标识符(这是'assert'检查的内容)。 – 2010-12-17 18:04:32