iOS:lldb EXC_BAD_ACCESS自定义单元 [英] iOS: lldb EXC_BAD_ACCESS Custom Cell

查看:83
本文介绍了iOS:lldb EXC_BAD_ACCESS自定义单元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"LibraryListingCell";

    InSeasonCell *cell = (InSeasonCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"InSeasonCellView" owner:self options:nil];
        cell = [_cell autorelease];
        _cell = nil;
    }
    if(_dataController!=NULL){
        Product *productAtIndex = [_dataController objectInListAtIndex:indexPath.row];
        // Configure the cell...
        if (productAtIndex.name != nil && productAtIndex.week != nil && productAtIndex.image != nil) {
            cell.name.text = productAtIndex.name;
            cell.week.text = productAtIndex.week;
            cell.image.image = productAtIndex.image;
        }
    }

    return cell;
}

cell.name.text cell.week.text cell.image.text 的消息错误.可以肯定这是内存管理错误.据我所知,我已适当保留并释放了该文件.该应用程序将在启动时崩溃,有时可以正常加载所有内容,但在滚动时会崩溃.任何有关内存管理的帮助或指示,都将受到赞赏.

Message ERROR for cell.name.text cell.week.text cell.image.text. Pretty sure it is a memory management error. I have retained and released properly to the best of my knowledge. The application will crash upon launch, sometimes it loads everything fine, but when you scroll it crashes. Any help or pointers about memory management is appreciated.

推荐答案

代替此:

 if (cell == nil) {
    [[NSBundle mainBundle] loadNibNamed:@"InSeasonCellView" owner:self options:nil];
    cell = [_cell autorelease];
    _cell = nil;
  }

您发送了自动释放消息并将其设置为nil,稍后您尝试访问该释放的cell.

You sent autorelease message and set it to nil, later you are trying to access that released cell.

我认为应该是:

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

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

这篇关于iOS:lldb EXC_BAD_ACCESS自定义单元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆