jeudi 30 juin 2016

Check which ViewController made a segue (from the destination ViewController)

I have a code that gives random segues to my 12 ViewControllers.

In ViewController1 it looks like this;

let segues = ["1-2", "1-3", "1-4", "1-5", "1-6", "1-7", "1-8", "1-9", "1-10", "1-11", "1-12"]
        let index = Int(arc4random_uniform(UInt32(segues.count)))
        let segueName = segues[index]
        self.performSegueWithIdentifier(segueName, sender: self)

And in ViewController 2 it looks the same, but the segue names change to;

let segues = ["2-1", "2-3", "2-4", "2-5", "2-6", "2-7", "2-8", "2-9", "2-10", "2-11", "2-12"]

(The "1" changes into a "2") - and so forth for all 12 ViewControllers.

.

Now, what I want to do is delete the ViewControllers that has already been shown, so that the next segue won't go back to any of the previous ViewControllers.

Example:

• ViewController1 makes a segue to ViewController2 ("1-2")

• ViewController2 deletes the segue "2-1" from the array segues

• ViewController2 then makes a segue to ViewController3 "1-3"

• ViewController3 deletes the segue "3-1" and "3-2"

and so on...

Aucun commentaire:

Enregistrer un commentaire