0
votes

when user clicked button

let uvc: UINavigationController =
            self.storyboard?.instantiateViewController(withIdentifier: "nationSelect") as! UINavigationController

uvc.modalTransitionStyle = UIModalTransitionStyle.coverVertical
self.present(uvc, animated: true, completion: nil)

run this code.

identifier:nationSelect storyboard img

cell, closebutton, VC segue unwind img

and button vc have this function

@IBAction func unwindFromPostCodeSelectionView(_ sender: UIStoryboardSegue) {
    print("unwindFromPostCodeSelectionView")
}

and nationSelect VC

when collectionview's cell clicked run this code

performSegue(withIdentifier: unwind, sender: nil)

and prepare function

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    guard let identifier = segue.identifier, identifier == unwind else{
        return
    }
    guard let vc = segue.destination as? CurationRequestViewController else {
        return
    }

    vc.getAddress.setTitle( (continent.text ?? " ") + " " + nation , for: .normal)
}

but i got this error

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

help me plz!!!

1
what is unwind ? where did you define this ?Shauket Sheikh
I think you have omitted an identifier. Give the identifier to it and check by using if-statement : if segue.identifier == "yourId" { // Do something }Mannopson
@ShauketSheikh unwind is String in nationSelect ViewControllergreatsk
check unwind is an option string ? if it is option then change it to normal one.Shauket Sheikh
unwind String is define letgreatsk

1 Answers

1
votes

Looks like you are trying to implement unwind segue and you missed to specify the identifier for unwind segue.

Here are the steps to properly implement unwind segue:

Step 1: If you are trying to implement unwind segue from Vc2 to Vc1 (Coming back to VC1 from VC2) then in VC1 add the IBAction as

@IBAction func unwindToViewController1(segue : UIStoryboardSegue) {
     //you will get control back here when you unwind
}

Step 2: Open storyboard, select VC2 and control drag from ViewController to Exit option in storyboard as shown below

enter image description here

This should show a popover and the method you just declared select it.

Step 3: (Step I think you missed) Select the unwind segue you just added and provide a identifier to it.

enter image description here

Step 4: Now whenever you wanna return back to VC1 you can simply call

self.performSegue(withIdentifier: "unwindSegueToViewController1", sender: nil)

Hope it helps :) Happy coding