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

标签 objective-c ios ipad uitableview

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/

相关文章:

iOS后台执行和防止应用程序被挂起/终止

objective-c - 用于 Google 文档的 iOS Objective-C 包装器

objective-c - Sqlite 使用 void 方法绑定(bind)文本?

objective-c - iPhone 测试 : testing IBOutlets

html - ios 上自定义图标字体上的奇怪水平线

iphone - 我如何在导航 Controller 中弹出

iphone - 带有 "Go"按钮而不是返回的 iOS 键盘

ios - 在 Objective-C 中使用全局变量

ios - 如何同时处理三个请求正确创建并发队列

ios - 在 iOS 中创建具有不同可触摸区域的圆圈