views:

65

answers:

1

I create my own nib, and class for it. I hooked up all the controls to the class in interface builder. When I run it it runs fine. The only problem is that when I scrole the tableview it crashes. Any ideas what the error could be? I've been trying to fix this for a while to no avail. It gives an EXC_BAD_ACCESS which I'm not sure how to debug.

int cellType = [streamDataProvider cellTypeForIndex:indexPath.row];

if(cellType == HOP_GRAFITTI){
    static NSString *CellIdentifier = @"HopGrafittiStreamCell";
    HopGrafittiStreamCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"HopGrafittiStreamCell" owner:self options:nil];
        cell = (HopGrafittiStreamCell *)[nib objectAtIndex:0];
        [cell retain];
    }

    [cell.username setText: [streamDataProvider userNameForIndex:indexPath.row]];
    [cell.venuename setText: [streamDataProvider venueNameForIndex:indexPath.row]];        
    [cell.grafittiText setText: [streamDataProvider grafittiForIndex:indexPath.row]];                
    return cell;
}
A: 

Should you ever need it again, here's a helpful way to debug an EXC_BAD_ACCESS error by setting a symbolic breakpoint. If ran in debug mode, the debugger will break at the point of EXC_BAD_ACCESS giving you the opportunity to look at the stack trace and work out what caused the problem:

  • Open the debug window
  • Open the breakpoints window (Show Breakpoints) on the top right
  • Double click the row that reads 'Double-Click for symbol'
  • type in objc_exception_throw and press return

You can leave this in your project permanently as it will always be helpful every time you run into an EXC_BAD_ACCESS error.

Hope this helps

Matt
`EXC_BAD_ACCESS` isn't an Objective-C exception, it's a *kernel* exception—i.e., the process has crashed outright. You can get this in any program, whether or not it uses the Obj-C runtime; a plain C program can produce such a crash. This will trip the debugger anyway; there is no need to set a breakpoint. Moreover, the debugger is not very helpful for debugging `EXC_BAD_ACCESS` in Objective-C applications, where it usually indicates a message sent to a dead object. In those cases, the Zombies instrument is much more useful for hunting down the cause of the erroneous death of the object.
Peter Hosey