Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to perform a push segue from a navigation controller, after dismissing a modal that was previously presented over the navigation controller.

Inside modal (UIViewController):

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

Inside SearchNavigationController:

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

The issue is that when I hit return, I get this error:

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

The segue is present in my storyboard, going from the UINavigationController to the next view.

enter image description here

EDIT: tried this, where _sender is declared in SingleSearchViewcontroller as var _sender = self and it did not work.

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "searchNavigationToSingleSearch" {
            let singleVC = segue.destinationViewController as! SingleSearchViewController

            singleVC._sender = self
        }
    }
like image 557
mattgabor Avatar asked Oct 31 '22 22:10

mattgabor


1 Answers

Update your code as,

func textFieldShouldReturn(textField: UITextField) -> Bool {
    var searchNav = SearchNavigationController()
    self.dismissViewControllerAnimated(true, completion: {self.presentingViewController.goToNextView()})
    return true
}
like image 98
Ashish P. Avatar answered Nov 15 '22 07:11

Ashish P.