开发者

UITableView titleForHeaderInSection prints headers to console twice then crashes

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 th开发者_如何学Pythonat 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


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:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜