我如何关闭模态转场然后将转场推送到新的视图控制器

How can I dismiss a modal segue then perform push segue to new view controller

我正在尝试从 navigation controller 执行 push segue,然后关闭之前在 navigation controller 上显示的 modal

内部模态(UIViewController):

func textFieldShouldReturn(textField: UITextField) -> Bool {
    var searchNav = SearchNavigationController()
    self.dismissViewControllerAnimated(true, completion: {searchNav.goToNextView()})
    return true
}

里面 SearchNavigationController:

func goToNextView() {
    performSegueWithIdentifier("searchNavigationToNextView", sender: self)
}

问题是当我点击 return 时,我得到了这个错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver () has no segue with identifier 'searchNavigationToNextView''

我的 storyboard 中出现了 segue,从 UINavigationControllernext 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
        }
    }

将您的代码更新为,

func textFieldShouldReturn(textField: UITextField) -> Bool {
    var searchNav = SearchNavigationController()
    self.dismissViewControllerAnimated(true, completion: {self.presentingViewController.goToNextView()})
    return true
}

我遇到了与 mattgabor 相同的问题,我尝试了 Ashish 的解决方案,但它对我不起作用。

我在代码中遇到的问题是,在 "dismissViewControllerAnimated()" 的完成块内,当我想从我之前的 "self.presentingViewController" 调用方法时,属性 "self.presentingViewController" =21=] 执行推送(本例中的方法 "goToNextView()")

所以我的解决方案就是在调用 "dismissViewControllerAnimated()" 之前创建一个变量来保存前一个 viewController。使用当前示例,它看起来像这样:

    func textFieldShouldReturn(textField: UITextField) -> Bool {
    if let searchNav = self.presentingViewController as? SearchNavigationController {
        self.dismissViewControllerAnimated(true) {
            searchNav.goToNextView()
        }
    }
    return true
 }