views:

85

answers:

1

In the method below titleForHeaderInSection, for some reason the NSLog prints out the headers twice and then the app crashes in objc_msgSend. I can't understand why this would cause the app to crash?

It would seem from research that crashes in objc_msgSend are caused by sending messages to already freed objects, but is that the case here?

My sectionNames array is populated in viewDidLoad.

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {   

    NSString *title = nil;
    title=[sectionNames objectAtIndex:section];
    NSLog(title);
    return title;
}

Thanks

+1  A: 

How are you populating your sectionNames array? It's possible that the array, not the string, is getting released prematurely.

UPDATE:

Your problem is that +arrayWithArray: creates an autoreleased array, which gets released when the current run loop finishes. You need to either retain sectionNames or use -initWithArray:

Martin Gordon
`sectionNames = [NSMutableArray arrayWithArray:[aPOI.attributes allKeys]];` where aPOI is an instance variable and attributes is a dictionary
joec