Monday, May 16, 2016

Passing data with Unwind Segue in Swift Language – iOS 9

An unwind segue (sometimes called exit segue) can be used to navigate back through push, modal or popover segues (as if you popped the navigation item from the navigation bar, closed the popover or dismissed the modally presented view controller). On top of that you can actually unwind through not only one but a series of push/modal/popover segues, e.g. “go back” multiple steps in your navigation hierarchy with a single unwind action.
To enable the Unwind Segue you need to add some code first.
1
2
@IBAction func unwindToVC(segue: UIStoryboardSegue) {
}
You have to add this code in the view controller where you want to unwind (came back).

Unwind To View
Suppose you want to came back from second or third view to first view then you have to add the code in first view.
Then just connect any control(Which contains action) with the unwind segue.
Unwind SegueUnwind Segue
For check the particular view controller by unwind segue, use following code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@IBAction func unwindToVC(segue:UIStoryboardSegue) {
    if(segue.sourceViewController .isKindOfClass(ViewController2))
    {
        let alert = UIAlertView()
        alert.title = "UnwindSegue"
        alert.message = "Unwind from view 2"
        alert.addButtonWithTitle("Ok")
        alert.show()
    }
    if(segue.sourceViewController .isKindOfClass(ViewController3))
    {
        let alert = UIAlertView()
        alert.title = "UnwindSegue"
        alert.message = "Unwind from view 3"
        alert.addButtonWithTitle("Ok")
        alert.show()
    }
}

No comments:

Post a Comment