iphone - dequeueReusableCellWithIdentifier :identifier not picking up a loadNibNamed cell

标签 iphone ipad ios uitableview

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

相关文章:

ios - 如何在 SwiftUI 上登录 Facebook?

css - 如何让我的背景图像覆盖 Retina 设备的整个屏幕?

iphone - iOS - 如何正确访问数组中的对象属性?

iphone - GPS定位器

iphone - 我们可以从App Store for iPhone获取应用程序的版本号吗?

iphone - 只读属性上的 Core Plot CPLineStyle 编译错误

ios - CoreData 保存问题

iphone - 如何在iOS sdk中开发UIMockup?

ios - 检索下一个文本时,字符串逐个字母的动画会混淆

ios - 苹果使用哪种字体/字体大小作为 iOS 中的占位符