作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个简单的单元格 - 在 IB 中设计 - 并设置了 reuseIdentifier。下面的代码工作得很好。然而 - NSLog() 显示结果从未被缓存。
TableView Controller 类:
- (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;
这是为什么 - 因为它使事情变得更有效率?
谢谢,
数据。
最佳答案
创建表格 View 单元格的方式无法确保将单元格放入表格 View 中的可重用队列中。唯一的方法是使用
initWithStyle:reuseIdentifier:
Initializes a table cell with a style and a reuse identifier and returns it to the caller.
我的另一个 question
关于iphone - dequeueReusableCellWithIdentifier :identifier not picking up a loadNibNamed cell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4464380/
我是一名优秀的程序员,十分优秀!