开发者

app crash when click on back

When i navigate on click row i push the poinofinterestview but when i click back app crash. but if i comment [nextControllerp release]; it works or 5 or 6 time then it crashes

(void)tableView:(UITableView *)TableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

[TableView deselectRowAtIndexPath:indexPath animated:YES];

PointOfInterest *nextControllerp=[[PointOfInterest alloc] initWithNibName:@"PointOfInterest" bundle:nil]; 
        if([LocationList count]!=0 && [LocationListId count]!=0) 
  开发者_JAVA百科      { 
          nextControllerp.locName=[LocationList objectAtIndex:indexPath.row]; 
          nextControllerp.LocationId=[LocationListId objectAtIndex:indexPath.row]; 
          [self.navigationController pushViewController:nextControllerp animated:YES];
       } 
[nextControllerp release];

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil]; 
self.navigationItem.backBarButtonItem=backButton;

 [backButton release];
}


One thing I noticed -- your code will sometimes create a PointOfInterest object and then release it without doing anything with it. Move the creation/release into the if block.

That aside, you're using the correct idiom for pushing a new controller onto a nav controller -- i.e. init the controller, push it onto the nav controller, then call release immediately.

I believe your crash is being caused by something not shown in the code you've posted. The fact that commenting out the release line causes it to crash less might indicate that there's some code somewhere still trying to access your new viewcontroller after it's been dismissed from the nav stack (because normally at the point of dismissal it would be released and dealloc'd).

Just out of curiosity, does removing the bit of code that sets the Back button item affect the crashing in any way? Trying commenting out the last three lines.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜