iphone - UITableViewCell 子类不工作

标签 iphone ios cocoa-touch uitableview

为什么我的单元格不会显示在表格中的任何想法。它在这段代码处崩溃了...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"SetTableViewCell";
    SetTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil){        
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"SetTableViewCell" owner:nil options:nil];

        for(id currentObject in topLevelObjects)
        {
            if([currentObject isKindOfClass:[SetTableViewCell class]])
            {
                cell = (SetTableViewCell *)currentObject;
                break;
            }
        }
    }
    [self configureCell:cell atIndexPath:indexPath];

    return cell;
}

最佳答案

在这种情况下最常见的事情是忘记将界面生成器中的 UITableViewCell 对象设置为 SetTableViewCell 类

从 Identity Inspector 仔细检查并确保自定义类设置为 SetTableViewCell

enter image description here

关于iphone - UITableViewCell 子类不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9050704/

相关文章:

ios - [NSDate date] 在多个设备中的不同结果

ios - UIButton 事件跟踪 Google Analytics(Swift)

ios - 核心数据 : How to check if value is compatible with attribute?

iphone - ScrollView 一次只滚动一项

ios - 运行序列时为 Action 动态分配参数

ios - 与 PFObject 子类的一对一关系因循环引用而失败

iphone - 如何在IB中使用UIScrollView?

iphone - iOS 5中的Twitter使用ARC泄漏内存

iphone - 对 Core Data 中获取的属性设置限制

iphone - 谁能告诉我如何使用 libHaru 库创建带有文本注释的 PDF