【发布时间】:2010-12-16 18:57:51
【问题描述】:
我有一个简单的单元格——在 IB 中设计——并设置了重用标识符。下面的代码工作得很好。但是 - NSLog() 显示结果永远不会被缓存。
表格视图控制器类:
- (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?只是想澄清你的问题。
-
确实是的 - 并且它们已经设置了一个单元格标识符(这是“断言”检查的内容)。
标签: iphone ipad ios uitableview