gpt4 book ai didi

iphone - dequeueReusableCellWithIdentifier :identifier not picking up a loadNibNamed cell

转载 作者:行者123 更新时间:2023-11-28 17:47:46 25 4
gpt4 key购买 nike

我有一个简单的单元格 - 在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com