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

為{幸葍}努か 提交于 2019-12-05 10:18:46

Update your code as,

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

I had the same issue that mattgabor had, and i tried Ashish's solution but it didn't work for me.

The problem i had in my code was that inside the completion block of "dismissViewControllerAnimated()", the propery "self.presentingViewController" was already nil when i wanted to call the method from my previous viewController that performed the push (the method "goToNextView()" in this example)

So my solution was just to create a variable to hold the previous viewController before calling "dismissViewControllerAnimated()". Using the current example, it would look like this:

    func textFieldShouldReturn(textField: UITextField) -> Bool {
    if let searchNav = self.presentingViewController as? SearchNavigationController {
        self.dismissViewControllerAnimated(true) {
            searchNav.goToNextView()
        }
    }
    return true
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!