2011-03-04 208 views
0

当我浏览点击行我推兴趣点,但是当我点击回应用程序崩溃。 但如果我评论[nextControllerp发布];它的工作原理或5或6的时间,然后它崩溃应用程序崩溃当点击回

(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) 
     { 
      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]; 
} 

回答

1

一两件事我注意到 - 你的代码,有时会创建一个PointOfInterest对象,然后释放它没有做任何事的。将创建/版本移动到if区块。除此之外,您正在使用正确的习惯用法将新控制器推到导航控制器上 - 即初始化控制器,将其推到导航控制器上,然后立即调用释放。

我相信你的崩溃是由你发布的代码中没有显示的东西引起的。注释掉release行会导致它崩溃的事实可能表明在某些代码仍然试图访问您的新viewcontroller后,它已从nav stack中解散(因为通常在解雇时它会被释放并释放dealloc' d)。

出于好奇,删除设置后退按钮项的代码是否会以任何方式影响崩溃?尝试评论最后三行。

+0

感谢您的回复。 – shivraj 2011-03-04 12:35:22

相关问题