iOS5 selecting an NSObject in UITableView = EXC_BAD_ACCESS
I'm struggling with a problem that I've been trying to fix for 3 days now, and I need help.

In my TicketTableViewController.m file, i'm creating an NSMutableArray of a custom NSObject (Ticket), with each Ticket having values;

    Ticket *ticketFound = [[Ticket alloc] initWithTicketNumber:ticketString locationNumber:locationString clerkNumber:clerkString approvedState:approvedState approvedDetail:approvedDetail totalNumber:[totalString floatValue] tipNumber:[tipString floatValue] balanceNumber:[subtotalString floatValue] ticketItemsArray:nil ticketItemsDict:nil];

I'm adding these to arrays depending on the ticket's approval state;

    if ([approvedState isEqualToString:@"approved"]) {
            [self.approvedTickets addObject:ticketFound];
        }
        else if ([approvedState isEqualToString:@"declined"]) {
            [self.declinedTickets addObject:ticketFound];

        }
        else if ([approvedState isEqualToString:@""]){
            [self.openTickets addObject:ticketFound];
        }


I'm then adding these arrays to NSDictionary's, and then to a global `NSArray *tickets` as per <a href="http://www.iphonesdkarticles.com/2009/01/uitableview-sectioned-table-view.html">this tutorial</a>;

    NSDictionary *openDict = [NSDictionary dictionaryWithObject:self.openTickets forKey:@"tickets"];
    NSDictionary *decDict = [NSDictionary dictionaryWithObject:self.declinedTickets forKey:@"tickets"];
    NSDictionary *approvDict = [NSDictionary dictionaryWithObject:self.approvedTickets forKey:@"tickets"];
    
    [self.tickets addObject:openDict];
    [self.tickets addObject:decDict];
    [self.tickets addObject:approvDict];

With this global `NSArray *tickets` set, I can then display every ticket in a sectioned UITableView (as per the tutorial). I'm using custom cells that pull information from each ticket in the array, and display them;

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"TicketCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    NSDictionary *dictionary = [self.tickets objectAtIndex:indexPath.section];
    NSArray *array = [dictionary objectForKey:@"tickets"];
    Ticket *ticket = [array objectAtIndex:indexPath.row];

    UILabel *locationLabel = (UILabel *)[cell viewWithTag:100];
    locationLabel.text = [NSString stringWithFormat:@"Location: %@", ticket.locationNumber];
    UILabel *ticketLabel = (UILabel *)[cell viewWithTag:101];
    ticketLabel.text = [NSString stringWithFormat:@"Ticket: %@", ticket.ticketNumber];
    UILabel *balanceLabel = (UILabel *)[cell viewWithTag:102];
    balanceLabel.text = [NSString stringWithFormat:@"$%.2f", ticket.balanceNumber];   
        
    return cell;    }

This is working perfectly for me (albeit another issue which I'll come onto once this one is solved). My problem then comes when a user selects a ticket from the UITableView. If I try and call any part of data from the ticket at the selected row, the app crashes with just an `EXC_BAD_ACCESS` error. Here's my code;

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {    
  
    NSDictionary *dictionary = [self.tickets objectAtIndex:indexPath.section];
    NSArray *array = [dictionary objectForKey:@"tickets"];
    Ticket *ticket = [array objectAtIndex:indexPath.row];
    
    NSLog(@"float: %@", ticket.balanceNumber); //this causes the crash   }

I know I'm returning a Ticket(NSObject) because if I put `NSLog(@"class: %@", [ticket class]);` and change the `Ticket *ticket...` to `id ticket...` it returns a Ticket(NSObject).

I appreciate any advice.

Thanks in advance.

Regards,

Dan
iOS5 selecting an NSObject in UITableView = EXC_BAD_ACCESS
===

I'm struggling with a problem that I've been trying to fix for 3 days now, and I need help.

In my TicketTableViewController.m file, i'm creating an NSMutableArray of a custom NSObject (Ticket), with each Ticket having values;

    Ticket *ticketFound = [[Ticket alloc] initWithTicketNumber:ticketString locationNumber:locationString clerkNumber:clerkString approvedState:approvedState approvedDetail:approvedDetail totalNumber:[totalString floatValue] tipNumber:[tipString floatValue] balanceNumber:[subtotalString floatValue] ticketItemsArray:nil ticketItemsDict:nil];

I'm adding these to arrays depending on the ticket's approval state;

    if ([approvedState isEqualToString:@"approved"]) {
            [self.approvedTickets addObject:ticketFound];
        }
        else if ([approvedState isEqualToString:@"declined"]) {
            [self.declinedTickets addObject:ticketFound];

        }
        else if ([approvedState isEqualToString:@""]){
            [self.openTickets addObject:ticketFound];
        }


I'm then adding these arrays to NSDictionary's, and then to a global `NSArray *tickets` as per <a href="http://www.iphonesdkarticles.com/2009/01/uitableview-sectioned-table-view.html">this tutorial</a>;

    NSDictionary *openDict = [NSDictionary dictionaryWithObject:self.openTickets forKey:@"tickets"];
    NSDictionary *decDict = [NSDictionary dictionaryWithObject:self.declinedTickets forKey:@"tickets"];
    NSDictionary *approvDict = [NSDictionary dictionaryWithObject:self.approvedTickets forKey:@"tickets"];
    
    [self.tickets addObject:openDict];
    [self.tickets addObject:decDict];
    [self.tickets addObject:approvDict];

With this global `NSArray *tickets` set, I can then display every ticket in a sectioned UITableView (as per the tutorial). I'm using custom cells that pull information from each ticket in the array, and display them;

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"TicketCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    NSDictionary *dictionary = [self.tickets objectAtIndex:indexPath.section];
    NSArray *array = [dictionary objectForKey:@"tickets"];
    Ticket *ticket = [array objectAtIndex:indexPath.row];

    UILabel *locationLabel = (UILabel *)[cell viewWithTag:100];
    locationLabel.text = [NSString stringWithFormat:@"Location: %@", ticket.locationNumber];
    UILabel *ticketLabel = (UILabel *)[cell viewWithTag:101];
    ticketLabel.text = [NSString stringWithFormat:@"Ticket: %@", ticket.ticketNumber];
    UILabel *balanceLabel = (UILabel *)[cell viewWithTag:102];
    balanceLabel.text = [NSString stringWithFormat:@"$%.2f", ticket.balanceNumber];   
        
    return cell;    }

This is working perfectly for me (albeit another issue which I'll come onto once this one is solved). My problem then comes when a user selects a ticket from the UITableView. If I try and call any part of data from the ticket at the selected row, the app crashes with just an `EXC_BAD_ACCESS` error. Here's my code;

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {    
  
    NSDictionary *dictionary = [self.tickets objectAtIndex:indexPath.section];
    NSArray *array = [dictionary objectForKey:@"tickets"];
    Ticket *ticket = [array objectAtIndex:indexPath.row];
    
    NSLog(@"float: %@", ticket.balanceNumber); //this causes the crash   }

I know I'm returning a Ticket(NSObject) because if I put `NSLog(@"class: %@", [ticket class]);` and change the `Ticket *ticket...` to `id ticket...` it returns a Ticket(NSObject).

I appreciate any advice.

Thanks in advance.

Regards,

Dan