所以我为我的学校做了一个rss阅读器,并完成了代码。我运行了测试,它给了我这个错误。下面是它引用的代码:

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

        cell = 
         [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle  
                                reuseIdentifier:CellIdentifier];

    }

以下是输出中的错误:

2012-10-04 20:13:05.356 Reader[4390:c07] * Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:4460 2012-10-04 20:13:05.357 Reader[4390:c07] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard' * First throw call stack: (0x1c91012 0x10cee7e 0x1c90e78 0xb64f35 0xc7d14 0x39ff 0xd0f4b 0xd101f 0xb980b 0xca19b 0x6692d 0x10e26b0 0x228dfc0 0x228233c 0x228deaf 0x1058cd 0x4e1a6 0x4ccbf 0x4cbd9 0x4be34 0x4bc6e 0x4ca29 0x4f922 0xf9fec 0x46bc4 0x47311 0x2cf3 0x137b7 0x13da7 0x14fab 0x26315 0x2724b 0x18cf8 0x1becdf9 0x1becad0 0x1c06bf5 0x1c06962 0x1c37bb6 0x1c36f44 0x1c36e1b 0x147da 0x1665c 0x2a02 0x2935) libc++abi.dylib: terminate called throwing an exception

下面是它在错误屏幕上显示的代码:

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

请帮助!


当前回答

确保故事板中单元格的CellIdentifier ==标识符,两个名称是相同的。希望这对你有用

其他回答

只是对答案的补充: 可能有一段时间你把所有的东西都设置对了,但你可能不小心在你的.xib中添加了一些其他的ui,比如UIButton: 只要删除额外的UI,它就能工作。

虽然这个问题相当古老,但还有另一种可能性: 如果您正在使用故事板,您只需在故事板中设置CellIdentifier。

所以如果你的CellIdentifier是"Cell",只需设置"Identifier"属性:

确保在此之后清理构建。XCode有时在故事板更新方面会有一些问题

在Swift中,这个问题可以通过添加以下代码来解决

viewDidLoad

方法。

tableView.registerClass(UITableViewCell.classForKeyedArchiver(), forCellReuseIdentifier: "your_reuse_identifier")

我也有同样的问题

static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

   if (cell==nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

    }

解决了

我在故事板中正确地设置了一切,并进行了干净的构建,但一直得到错误“必须为标识符注册一个nib或类或连接故事板中的原型单元格”

[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];

纠正了错误,但我还是不知所措。我没有使用“自定义单元格”,只是一个嵌入tableview的视图。我已经声明了视图控制器作为委托和数据源,并确保单元格标识符匹配文件。这是怎么回事?