gpt4 book ai didi

ios - dequeueReusableCellWithIdentifier 中的断言失败 :forIndexPath:

转载 作者:行者123 更新时间:2023-11-30 13:50:48 25 4
gpt4 key购买 nike

所以我正在为我的学校制作一个 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]));
}
}

请帮忙!

最佳答案

您正在使用dequeueReusableCellWithIdentifier:forIndexPath:方法。 documentation对于该方法来说:

Important: You must register a class or nib file using the registerNib:forCellReuseIdentifier: or registerClass:forCellReuseIdentifier: method before calling this method.

您没有为重用标识符注册 Nib 或类 "Cell" .

查看您的代码,您似乎期望出队方法返回 nil如果它没有手机可以给你。您需要使用dequeueReusableCellWithIdentifier:对于该行为:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

请注意dequeueReusableCellWithIdentifier:dequeueReusableCellWithIdentifier:forIndexPath:是不同的方法。请参阅文档 the formerthe latter .

如果您想了解为什么要使用dequeueReusableCellWithIdentifier:forIndexPath: , check out this Q&A .

关于ios - dequeueReusableCellWithIdentifier 中的断言失败 :forIndexPath:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34305239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com