我有兩個問題,我不明白,希望有人能幫助。UINavigationController瘋了嗎?
此代碼不適用於從分割視圖控制器中獲取現有的UINavigationController層次結構並使用它接管屏幕。我只是得到一個黑屏
UINavigationController* myself = self.navigationController;
[myself removeFromParentViewController];
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"QuestionnaireViewController"];
[myself pushViewController:controller animated:YES];
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
app.window.rootViewController = myself;
但是,這段代碼確實有效。爲什麼我可以將rootViewController設置爲新的UINavigationController而不是self.navigationController?
UINavigationController *navController = [[UINavigationController alloc] init];
UINavigationController* myself = self.navigationController;
[myself removeFromParentViewController];
navController.viewControllers = myself.viewControllers;
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"QuestionnaireViewController"];
[navController pushViewController:controller animated:YES];
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
app.window.rootViewController = navController;
我的第二個問題是當用戶「返回」時將導航控制器恢復到splitViewController。我從經驗中知道,我可以將一個新的UINavigationController分配給detailView,但我無法分配self.navigationController。
我認爲問題是相同的問題。出於某種原因,新的UINavigationController與UIView的navigationController不一樣。爲什麼?
我決定用一個modalViewController代替。如果需要,我可以將其嵌入到NavigationController中,並輕鬆解除它以返回到之前的splitViewController。 –