2013-03-31 24 views
0
- (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; 
} 

消息ERROR爲cell.name.text cell.week.text cell.image.text。很確定這是一個內存管理錯誤。盡我所知,我保留並正確發佈。應用程序在啓動時會崩潰,有時會加載一切正常,但是當您滾動它時會崩潰。任何關於內存管理的幫助或指針,我都讚賞。的iOS:LLDB EXC_BAD_ACCESS自定單元

回答

3

取而代之的是:

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

您發送自動釋放消息,並將其設置爲nil,以後你試圖訪問該發佈cell

我認爲它應該是爲:

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

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

_cell是一個自定義的UITableViewCell和訪問它作爲一個IBOutlet。我不認爲我必須發佈一個IBOutlet或分配一個。我會嘗試使用IBOutlet而不釋放它。 – wwjdm

+0

我正在使用本教程http://www.iphonedevcentral.com/customize-that-uiviewcell-part-1-using-interface-builder/。 – wwjdm

+0

有一個自定義單元格.h .m和xib文件。我將如何加載(自定義xib),而不是創建一個新的UITableViewCell – wwjdm