簡體   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