iphone - 如何解决 uitableview 中对象的释放问题?

标签 iphone objective-c cocoa-touch uitableview

我有一个包含高单元格的表格 View 。高度300左右。这些单元是定制的,并且有一个相关的 Nib 。在 cellForRowAtIndexPath 中,我使用 indexPath.row 访问数组中的对象。该对象具有属性,我将这些属性分配给自定义单元格上的标签。这对于前两个单元格来说效果很好。一旦我滚动足够多以创建第三个单元格,应用程序就会崩溃。

我设置了 NSZombieEnabled,这是输出:

2010-04-19 21:48:13.360 MyApp[54463:207] *** -[CALayer release]: message sent to deallocated instance 0xfc4e50
(gdb) continue
2010-04-19 21:48:18.382 MyApp[54463:207] *** NSInvocation: warning: object 0xfc4e50 of class '_NSZombie_CALayer' does not implement methodSignatureForSelector: -- trouble ahead
2010-04-19 21:48:18.383 MyApp[54463:207] *** NSInvocation: warning: object 0xfc4e50 of class '_NSZombie_CALayer' does not implement doesNotRecognizeSelector: -- abort
(gdb) continue
Program received signal:  “EXC_BAD_ACCESS”.
(gdb) 

我不确定释放了什么。我如何追查其来源?

-- 编辑--

添加 cellForRowAtIndexPath 实现:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

OrderCell *cell = (OrderCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"OrderCellView" owner:self options:nil];
    cell = [nib objectAtIndex:0];
}

// Set up the cell...
if(self.rows != nil){
    id obj = [self.rows objectAtIndex:indexPath.row];
    cell.orderId.text = [NSString stringWithFormat:@"%@",[obj objectForKey:@"OrderId"]];
    cell.orderName.text = [NSString stringWithFormat:@"%@",[obj objectForKey:@"OrderName"]];
}

return cell;
}

最佳答案

解决方案如下:

正如OP中提到的,这是一个自定义单元并加载一个 Nib 。我正在使用

static NSString *CellIdentifier = @"Cell";

但没有在 IB 中为标识符指定任何内容。里面一片空白。输入“Cell”作为标识符后,它现在可以正常工作了。我猜测 Nib 是从代码中创建的单元对象中释放的,因为一个有标识符,而另一个没有。

我对为什么 IB 标识符在这种情况下对于单元格如此重要的详细信息感兴趣......如果有人能够提供一些详细信息。

关于iphone - 如何解决 uitableview 中对象的释放问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2672621/

相关文章:

javascript - 如何在 iOS UIWebView 中获取网页的所有 <img src>?

ios - iOS:未呈现NSMutableAttributedString.AddAttributes。 (Xamarin)

ios - UINavigationController pushViewController 在中途暂停/卡住

iPhone - 使图像适应视网膜显示

php - iPhone表情插入MySQL却变成空值

iphone - iOS 后台 Location 不发送 http 请求

iphone - [iPhone 和网络服务] : REST vs SOAP

ios - 更改容器高度后 UIButton 不可点击

ios - 删除一个 Realm 对象及其所有 RLMArrays

iphone - 通过 UIManagedDocument 加速将对象插入到 Core Data 中?