iphone - 添加自定义 UITableViewCell 会使模拟器崩溃

标签 iphone objective-c cocoa xcode macos

我正在尝试使用自定义 UITableViewCell 构建我的应用程序。这是我的 UIViewController 中的代码,它将 viewCell 添加到表中:

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{   
    NSLog(@"------- Tableview --------");

    static NSString *myIdentifier = @"MyIdentifier";

    MyTableCell *cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:myIdentifier];
    if(cell == nil) {
        NSArray *cellView = [[NSBundle mainBundle] loadNibNamed:@"tblCellView" owner:self options:nil];
        cell = [cellView objectAtIndex:0];
    }

    [cell setLabelText:[NSString stringWithFormat:@"indexpath.row: %d", indexPath.row]];


    //cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:myIdentifier] autorelease];
    cell.textLabel.text = @"bös";
    return cell;
    }

如果我取消注释“返回单元格”上面的行,它会返回一个常规的 UITableViewCell ,没有任何错误,但是一旦我尝试实现我的自定义单元格,它就会因以下错误而崩溃:

------- Tableview -------- 2010-04-23 11:17:33.163 Golf[26935:40b] * Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-984.38/UITableView.m:4709 2010-04-23 11:17:33.164 Golf[26935:40b] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:' 2010-04-23 11:17:33.165 Golf[26935:40b] Stack: (

...

我已经按照正确的 socket 配置了 .xib 文件。 UITableViewCell 的标识符与我尝试从 NSBundle 加载的名称相对应

最佳答案

您还应该确保将 Interface Builder 中的自定义类类型设置为相应的类名称(在您的示例中为 MyTableCell),否则转换也将不起作用。

关于iphone - 添加自定义 UITableViewCell 会使模拟器崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2697428/

相关文章:

iphone - 在开头呈现模态视图

ios - 当主线程使用量增加时,IOS音频线程CPU使用率下降

iphone - 使用 CocoaHttpServer 或 iPhone 上的任何 http 服务器上传多个文件

objective-c - 10.6/Xcode 3.2 中的 NSCollectionView

iphone - AlertView 的 init 方法中的参数

objective-c - NSDateFormatter stringFromDate 不返回字符串

cocoa - 如何复制 Core Data 托管对象?

cocoa - 在一台用户 10.6.8 机器上崩溃,并将无法识别的选择器发送到类(class)

iphone - ALAssetsLibrary 的 enumerateGroupsWithTypes :usingBlock:failureBlock: "broken" in iOS 4. 是 3.4 吗?

objective-c - 如何将静态 NSFolder 图像添加到 cocoa 绑定(bind)表