0

我有一个 UITableViewController (CoffeeBeansViewController),它从 sqlite 表中查找值并在表中显示内容。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"RegionCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // Configure the cell...
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
    int rowCount = indexPath.row;
    CoffeeBeans *coffeeBeans = [self.theCoffees objectAtIndex:rowCount];
    cell.textLabel.text = coffeeBeans.region;
    cell.detailTextLabel.text = coffeeBeans.variety;

    return cell;  
}

退出函数后,程序崩溃并出现错误:线程 1:EXC_BAD_ACCESS (code =2, address=0*879fc0)。

libobjc.A.dylib`objc_release:
0xf90dd0:  pushl  %ebp
0xf90dd1:  movl   %esp, %ebp
0xf90dd3:  subl   $8, %esp
0xf90dd6:  calll  0xf90ddb                  ; objc_release + 11
0xf90ddb:  popl   %ecx
0xf90ddc:  movl   8(%ebp), %eax
0xf90ddf:  testl  %eax, %eax
0xf90de1:  je     0xf90e00                  ; objc_release + 48
0xf90de3:  movl   (%eax), %edx
0xf90de5:  movl   16(%edx), %edx
0xf90de8:  testb  $4, 2(%edx)               <error message is here>
0xf90dec:  je     0xf90e05                  ; objc_release + 53
0xf90dee:  movl   775957(%ecx), %ecx
0xf90df4:  movl   %ecx, 4(%esp)
0xf90df8:  movl   %eax, (%esp)
0xf90dfb:  calll  0xf9008c                  ; objc_msgSend
0xf90e00:  addl   $8, %esp
0xf90e03:  popl   %ebp
0xf90e04:  ret    
0xf90e05:  addl   $8, %esp
0xf90e08:  popl   %ebp
0xf90e09:  jmp    0

在 lh 列中,它突出显示线程 1 下的“0 objc_release”。

谁能帮我解决这个错误?谢谢。

4

1 回答 1

0

试试这个。还要调试整个代码并使 NSZombieEnabled 为 YES 以了解错误:

    CoffeeBeans *coffeeBeans = (CoffeeBeans *)[self.theCoffees objectAtIndex:rowCount];
    if(coffeeBeans)
    {
      if(coffeeBeans.region)
         cell.textLabel.text = coffeeBeans.region;

      if(coffeeBeans.variety)
         cell.detailTextLabel.text = coffeeBeans.variety;
    }
于 2012-10-04T08:35:09.660 回答