gpt4 book ai didi

objective-c - iOS - 加载自定义表格单元格导致第二次加载出错

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:55:08 25 4
gpt4 key购买 nike

I am working on an iPad app with a table view with standard cells, when a custom cell is selected, it should expand and load a custom nib file.对于第一个选择,它做得很好。

如果我选择一个标准单元格,它会很好地加载 Nib ,如果我再次选择它,它会恢复正常,在第二次加载时,它会抛出一个 EXC_BAD_ACCESS 错误(我不认为我将永远得到 xcodes 错误,似乎是最抽象的)。

我的代码在下面,这一行是当它使单元格出队以供重用时,第 3 行:

if([listCells objectAtIndex:indexPath.row] == @"open") {
NSLog(@"Loading open cell at %i", indexPath.row);
CustomMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomMessageCell"];
//Loads the nib file and grabs the last object, presumably the table cell, as it is the only object in the file.
if(cell==nil) {
cell = [[[[NSBundle mainBundle] loadNibNamed:@"CustomMessageCell" owner:self options:nil] lastObject] autorelease];
}
UILabel *message = (UILabel *) [cell viewWithTag:1];
UIButton *approve = (UIButton *)[cell viewWithTag:4];
message.text = @"Test";
return cell;

非常感谢任何帮助,谢谢!

最佳答案

你在真机上编译运行了吗?有时您会获得更多信息,然后仅在模拟上运行。

还有其他要检查的东西:

  • 你应该检查 IB 中的 Nib 文件的标识符是否已设置正确地传递给 CustomMessageCell。
  • 确保您在 IB 中的 subview 标识符设置正确。
  • 请注意,您不应自动释放该单元格,因为它已经由 lastObject 方法返回自动释放。这可能会导致崩溃的另一个原因。

也尝试运行您的应用程序(在真实设备上)并使用 Zombies 和 Leaks 分析工具对其进行分析。 (而不只是“运行”选择“配置文件”)。

希望这对您有所帮助。

关于objective-c - iOS - 加载自定义表格单元格导致第二次加载出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7865456/

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