iphone - 如何在多种单元格类型中使用新的 iOS 6 registerClass UITableView 方法

标签 iphone ios uitableview

我在使用 UITableView 的新 registerClass 方法时遇到了问题。我很好地注册了我的单元格,然后当我想制作一个单元格时,我这样做:

static NSString *imageIdentifier = @"image";
CustomCell *cell = [self.tableView dequeueReusableCellWithIdentifier:imageIdentifier];

if (!cell) {
    cell = [[CustomCell alloc] initWithQuestion:self.question reuseIdentifier:imageIdentifier];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}

这可能不是现代的方法,但我以前就是这样做的。问题是因为新的 registerClass 方法创建了一个新单元 如果队列中没有一个,则 if (!aCell) 检查失败,并且单元格未正确构建。

我没有使用这种新方法正确出列吗?

最佳答案

1) 在 prepareForReuse 中设置单元格(在您的情况下为 selectionStyle) UITableViewCell 子类的方法。

2) 设置dequeueReusableCellWithIdentifier:后面的单元格内容来电tableView:cellForRowAtIndexPath:委托(delegate)方法。
dequeueReusableCellWithIdentifier:如果您调用了 registerClass:,将始终返回一个单元格带有相应的标识符。

关于iphone - 如何在多种单元格类型中使用新的 iOS 6 registerClass UITableView 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13854789/

相关文章:

objective-c - 关于 Objective C 中的内存管理

ios - 寻找 UIImageView 的中心 UIImageView.center 意外的结果

ipad - UITableView 部分在设备旋转后失去交互

iphone - 如何将 JQuery 注入(inject) UIWebView 中的现有页面?

iphone - 在核心数据中列出共同的 friend

ios - 当应用程序被终止/强制退出时设置角标(Badge)计数

ios - 在 UITableView 上设置最小内容大小

iphone - UITableView 的非字母索引

javascript - 如何在 iPhone Safari 中获取触摸的 X/Y 位置?

iPhone UITableView 单元格保持选中状态