繁体   English   中英

iOS:自定义单元格lldb内存访问错误

[英]iOS: Custom Cell lldb Memory access error

仍然无法访问变量以加载到自定义单元格中。 我有一个名为InSeasonCell的xib,.h,.m。 我有一个IBOutlet InSeasonCell * _cell; 在rootviewcontroller的.h中。 访问我的productAtIndex值时出现lldb错误。 任何帮助都会很棒。 有人告诉我阅读《 Table View编程指南》。

我创造

_dataController = [[InSeasonProductDataController alloc] init];

它是rootviewcontroller中的init,但是传递给另一个用Product对象填充它的对象。

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

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

    return cell;
}

我查看了一下代码,发现正在将在一个类中创建的对象传递给另一个。 例如:

-(id)initWithDataController:(InSeasonProductDataController *)dataController spinner:      (UIActivityIndicatorView *)spinner{
       if(self = [super init]){
           _dataController = [dataController retain];
           _spinner = [spinner retain];
       }
       return self;
}

_dataController稍后在此方法中填充Product对象,然后将其释放。

要解决此错误,您需要在xib文件中单击单元格原型,然后在“属性检查”>“标识符”中插入与.m文件中相同的名称(我记下“ cell”):

在方法中:

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {....... Cell = [tableView dequeueReusableCellWithIdentifier:@“ cell”]; 单元格= [[MainCustomCell分配] initWithStyle:UITableViewCellStyleDefault重用标识符:@“单元格”];

我想到了。 我的Product对象初始化了变量,我必须为传入的每个变量做一个副本。这消除了lldb错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM