- (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;
}
cell.name.text cell.week.text cell.image.text 的消息错误。很确定这是一个内存管理错误。据我所知,我已妥善保留和发布。该应用程序会在启动时崩溃,有时它会加载一切正常,但当您滚动时它会崩溃。感谢您提供有关内存管理的任何帮助或指示。
最佳答案
取而代之的是:
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];
}
关于iOS:lldb EXC_BAD_ACCESS 自定义单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15726970/