How can I reject a modal segment and then push push segue into a new view controller

I am trying to execute a push segue from a navigation controller after rejecting the modal that was previously introduced in the navigation controller .

Inside the modal ( UIViewController ):

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

Inside the SearchNavigationController :

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

The problem is that when I press return, I get this error:

Application termination due to the uncaught exception "NSInvalidArgumentException", reason: "The receiver () does not have the identifier 'searchNavigationToNextView' '

Seg is present in my storyboard , moving 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 this did not work.

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier == "searchNavigationToSingleSearch" { let singleVC = segue.destinationViewController as! SingleSearchViewController singleVC._sender = self } } 
+4
source share
2 answers

Update your code as,

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

I had the same problem as mattgabor and I tried the Ashish solution, but this did not work for me.

The problem I had in my code was that inside the “rejectViewControllerAnimated ()” termination block, the “self.presentingViewController” property was already null when I wanted to call the method from my previous viewController that was pushing (the “goToNextView method” () "in this example)

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

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

All Articles