[英]Navigation controller crashing on second time
我在應用程序中使用了一個導航控制器。 我有一個主視圖(帶有主視圖控制器)和幾個選項視圖。 單擊主視圖工具欄上的按鈕時,導航控制器將查看選項視圖。
一切都按預期進行。 當我從導航控制器返回主視圖並再次嘗試進入選項視圖(即導航控制器)時,我的應用程序崩潰了。
以下是我的代碼,
//Jump to navigation controller from main view controller
optionsViewController *optionsView = [[optionsViewController alloc] initWithNibName:@"optionsView" bundle:nil];
navControllerSettings = [[UINavigationController alloc] initWithRootViewController:(UIViewController *) optionsView];
[self presentModalViewController:self.navControllerSettings animated:YES];
//Code to go back to main view from navigation controller
[self.navigationController dismissModalViewControllerAnimated:YES];
什么是處理導航控制器的正確機制? 我是否需要釋放/取消分配導航控制器或選項視圖?
示例代碼將更好地幫助您。
我有與此類似的問題,它在第二次嘗試時在presentModalViewController中崩潰。 該問題是由於在我展示的第一個UIViewController中調用viewDidAppear中的[self becomeFirstResponder]
而引起的,但是我在viewWillDisappear:中未能調用[self resignFirstResponder]
。
您的導航控制器僅設置一次,然后從其堆棧中推送和彈出其他視圖。
UINavigationController *navController = [[UINavigationController alloc] init];
UIViewController *yourMainViewController = [[yourMainViewControllerClass alloc] init];
// when you are ready to go to your options view
optionsViewController *optionsView = [[optionsViewController alloc] initWithNibName:@"optionsView" bundle:nil];
[navController pushViewController:optionsViewController animated:YES];
// the back button and the pop from the stack when it is hit is handled auto-magically for you
謝謝回復。
但是我的應用程序體系結構是,我有一個主視圖,上面沒有顯示任何東西,還具有工具欄。 單擊后,工具欄包含一個按鈕,該導航控制器已創建並顯示在屏幕上。
使用后退按鈕,我進入了主視圖。 但是然后在執行以下行時由於崩潰而無法繼續導航之后
[self presentModalViewController:self.navControllerSettings動畫:是];
這可能是什么問題?
維沙爾N
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.