我有一個導航堆棧包括:參考從模態呈現視圖控制器(目標c)
UINavigationViewController
-> WelcomeViewController
-> RoleViewController
我想在歡迎和角色之間添加一個模態的ViewController。我通過故事板添加一個ModalViewController,並從WelcomeViewController中的一個按鈕中爲ModalViewController分配一個segue(Modally)。這一切都很好,模態顯示很好。
現在我在ModalViewController中我想解除模態並從歡迎使用角色執行原始的segue。我在StackOverflow上進行了一些搜索,然後介紹瞭如何做到這一點的不同思路。最合理的方式被設置在這裏: Dismissviewcontroller and perform segue
UIViewController *parentController = self.presentingViewController;
[self dismissViewControllerAnimated:YES completion:^(void){
[parentController performSegueWithIdentifier:@"segue_gotoRole" sender:self];
}];
,將模態撤職,但不執行SEGUE和應用程序崩潰:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Receiver (<NavigationViewController: 0x78b96b80>) has no segue
with identifier 'segueToRole''
所以self.presentingViewController瞄準UINavigationViewController,而不是實際呈現模態的視圖控制器WelcomeViewController。 爲了成功,我需要找到一種方法來獲取在故事板中定義的呈現視圖控制器,作爲模式中的segue鼻祖。
我嘗試了很多不同的組合,例如self.parentViewController,self.presentationViewController,我甚至試圖循環遍歷導航堆棧以挑選出WelcomeViewController並將其作爲執行segue的對象專門指定,但似乎沒有任何效果。
請幫幫我。 :)
你是否從導航控制器或'WelcomeViewController'展示了你的視圖控制器? – ozgur
按下WelcomeViewController中的按鈕(嵌入在NavigationViewController中)時,將執行該模式。 –