所以我有一个根视图控制器,当用户按下它时会有一个按钮呈现另一个视图控制器.这个第二个控制器有一个关闭选项,它只返回到根视图控制器,当用户触摸它时,它会关闭当前视图控制器,因此它会返回到根视图控制器一秒钟并呈现另一个控制器.去我使用的第一个控制器:
let vc = FirstController()
self.present(vc, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
当在另一个视图控制器中时,我选择只关闭的按钮我这样做.
self.dismiss(animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
因此,对于需要解雇并呈现另一个的第二个控制器,我尝试了以下内容:
self.dismiss(animated: true, completion: {
let vc = SecondController()
self.present(vc, animated: true, completion: nil)
})
Run Code Online (Sandbox Code Playgroud)
但是我收到一个错误:
Warning: Attempt to present <UINavigationController: 0xa40c790> on <IIViewDeckController: 0xa843000> whose view is not in the window hierarchy!
Run Code Online (Sandbox Code Playgroud) 我试图在解雇之前提出的push segue一个navigation controller之后执行a .modalnavigation controller
内部modal(UIViewController):
func textFieldShouldReturn(textField: UITextField) -> Bool {
var searchNav = SearchNavigationController()
self.dismissViewControllerAnimated(true, completion: {searchNav.goToNextView()})
return true
}
Run Code Online (Sandbox Code Playgroud)
内部SearchNavigationController:
func goToNextView() {
performSegueWithIdentifier("searchNavigationToNextView", sender: self)
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我点击返回时,我收到此错误:
由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:'Receiver()没有带标识符'searchNavigationToNextView''的segue
segue存在于我的身边storyboard,从一直UINavigationController到另一个next view.
编辑:试过这个,其中_sender在SingleSearchViewcontroller中声明为var _sender = self,但它不起作用.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "searchNavigationToSingleSearch" {
let singleVC = segue.destinationViewController as! SingleSearchViewController
singleVC._sender = self
}
}
Run Code Online (Sandbox Code Playgroud)