1

I want to perform segue from View B to View C and I am calling method in class A. My segue method in Class B is-

//ViewController B


func nextViewAction() -> Void  {
        self.performSegueWithIdentifier("nextview", sender: self)
    }

And I am calling it in Class A like this-

//ViewController A



@IBAction func sideMenuAction(sender: AnyObject) {

        ViewClassB().nextViewAction()
}

enter image description here

But it crashing- Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver () has no segue with identifier 'nextview''

iDeveloper
  • 2,339
  • 2
  • 24
  • 38

4 Answers4

1

Have you set the name nextview for the segue between Controller B and Controller C? You can check by clicking on the segue between the two controllers, and then checking the Identifier value in the Attributes Inspector.

enter image description here

Fahim
  • 3,466
  • 1
  • 12
  • 18
0

What you can have is move to the third viewcontroller from first viewcontroller by skipping the second one use the code below..

class MyViewController: UIViewController, UINavigationControllerDelegate {

var viewControllerToInsertBelow : UIViewController?

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationController?.delegate = self
}

func pushTwoViewControllers() {
    if let viewController2 = self.storyboard?.instantiateViewControllerWithIdentifier("id1"),
        let viewController3 = self.storyboard?.instantiateViewControllerWithIdentifier("id2") { //change this to your identifiers
            self.viewControllerToInsertBelow = viewController2
            self.navigationController?.pushViewController(viewController3, animated: true)
    }
}

//MARK: - UINavigationControllerDelegate
func navigationController(navigationController: UINavigationController, didShowViewController viewController: UIViewController, animated: Bool) {
    if let vc = viewControllerToInsertBelow {
        viewControllerToInsertBelow = nil
        let index = navigationController.viewControllers.indexOf(viewController)!
        navigationController.viewControllers.insert(vc, atIndex: index)
    }
}

}

Reference : SO Post

Community
  • 1
  • 1
Saranjith
  • 11,242
  • 5
  • 69
  • 122
  • keep remember, I am not using `UINavigationController` at all – iDeveloper Apr 06 '17 at 08:58
  • please read [Is it possible to push a view controller without navigation controller?](http://stackoverflow.com/questions/6290097/is-it-possible-to-push-a-view-controller-without-navigation-controller) – Saranjith Apr 06 '17 at 09:02
0

Don't need to do any other code just use notification observer it will solve your problem.

Thank you

Swapnil Panchal
  • 387
  • 2
  • 5
  • 21
-1

I think you cannot trigger segue action from AViewController because what performSegue does is that :

Initiates the segue with the specified identifier from the current view controller's storyboard file.

Try implementing segue from A to C

Anuraj
  • 1,242
  • 10
  • 25