2013-03-31 46 views
0

仍然無法訪問要加載到自定義單元格的變量。我有一個名爲InSeasonCell的xib,.h,.m。我有一個IBOutlet InSeasonCell * _cell;在rootviewcontroller的.h中。我訪問我的productAtIndex值時遇到lldb錯誤。任何幫助都會很棒。我被告知要閱讀Table View Programming Guide。iOS:自定義單元格lldb內存訪問錯誤

創建

_dataController = [[InSeasonProductDataController alloc] init]; 

這是在RootViewController的初始化,但傳遞到與產品對象填充它的其他對象。

- (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對象填充併發布。

+0

這與你以前的問題有什麼不同http://stackoverflow.com/questions/15726970/ios-lldb-exc-bad-access-custom-cell,你已經接受了答案? –

+0

請注意,使用'registerNib:...'是加載自定義表格視圖單元格的更簡單的方法,請參閱http://stackoverflow.com/a/15591474/1187415。 –

+0

好的。謝謝,我會看看。 – wwjdm

回答

0

我想通了。我的產品對象初始化了變量,我必須爲每個傳入的變量都做一個副本。這樣擺脫了lldb錯誤。

0

爲了解決這個錯誤你在廈門國際銀行文件點擊需要對電池的原型,並在屬性檢查>標識插入相同的名字,你在.m文件有(我寫下「細胞」):

的方法

  • (的UITableViewCell *)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath { ....... 細胞= [的tableView dequeueReusableCellWithIdentifier:@ 「細胞」]; Cell = [[MainCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@「cell」];
+0

我不認爲這是錯誤。 – wwjdm

相關問題