简体   繁体   中英

iOS: Custom Cell lldb Memory access error

Still having trouble accessing variables to load into a custom cell. I have a xib, .h, .m named InSeasonCell. I have a IBOutlet InSeasonCell *_cell; in .h of rootviewcontroller. I get lldb error for accessing my productAtIndex values. Any help would be great. I was told to read the Table View Programming Guide.

I create

_dataController = [[InSeasonProductDataController alloc] init];

Which is init in the rootviewcontroller but passed to an other object which populates it with Product objects.

- (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;
}

I looked through my code and found that I am passing an object created in one class to the other. for example:

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

_dataController gets populated with Product objects later in this method and is released.

To solve this error you need in your xib file click on cell prototype and in Attribute inspection > Identifier insert the same name as you have in .m file (I write down "cell"):

in method:

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ....... Cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; Cell = [[MainCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];

I figured it out. My Product object initialized variables which I had to do a copy for each variable passed in. This got rid of the lldb error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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