开发者

UITableViewController crash on loading second time

I have a project where I want to open a UITableViewController after a UITableViewController via a UINavigationController. The thing is, it works the first time when it gets called by this function:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    SDMetadataEntity *entity = [self.optionItems objectAtIndex:indexPath.row];
    SudzcDetailViewController *detailViewController = [[SudzcDetailViewController alloc] init];
    detailViewController.refName = entity.Name;
    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];
    [entity release];
}

But when I press the back button on the navigation bar, and press the same item again, it crashes! It doesn't crash when I press a different item in the first UITableViewController. I would really like to learn from what I am doing wrong开发者_JAVA技巧!


You should not

[entity release]; 

because when you do

[self.optionItems objectAtIndex:indexPath.row];

you just fetching a pointer to it, not init/copy/retaining it.


You shouldn't be releasing entity.

You got that object from an array, you don't own it, so when you release it you may be causing it to be deallocated prematurely.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜