2011-03-04 114 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

相關問題