0

In my iPhone project I have an unwind segue exiting to PlayView. Inside unwind function as seen below I have a timer which delays for 0.05 seconds and then executes "autoSegue" function which in turn segues to other screens. This works fine on iOS 8 but for iOS7 devices, I am having to increase this delay significantly (up to 1.0 seconds), otherwise, it gives "another segue is already in progress" error.

Is there a way to execute "autoSegue" function automatically when any previous segues have been completed?

@IBAction func unwindToPlay (sender: UIStoryboardSegue){
    var del = NSTimer.scheduledTimerWithTimeInterval(0.05, target: self, selector: "autoSegue", userInfo: nil, repeats: false)
}

1 Answer 1

1

Call your autoSegue from viewDiDAppear rather than from your unwind segue. This will only get called after all animation transitions are complete. You won't need a timer. But you may want to set some kind of flag in your unwind segue to trigger the action only after an unwind segue has taken place.

EDIT
As this doesn't seem to be working for you, here is some code...

class RedViewController: UIViewController {
    var segueDidUnwind: Bool = false

    @IBAction func unwindToRed(sender: UIStoryboardSegue) {
        println("unwindToRed");
        segueDidUnwind = true
    }

    override func viewDidAppear(animated: Bool) {
        println("viewDidAppear");
        if (segueDidUnwind) {
            self.showVC()
            segueDidUnwind = false
        }
    }

    func showVC() {
        let vc =  UIViewController()
        self.presentViewController(vc, animated: true, completion: nil)
    }
}

It's an extension of this answer ... to which we can extend the logging...

actionForUnwindButton
prepareForSegue
unwindToRed
viewDidAppear

If viewDidAppear is not getting called in your code, you must have other structure to your project which is not apparent in the question.

Sign up to request clarification or add additional context in comments.

9 Comments

viewDidAppear does not get called on unwind segue.
@Tpos, I must have misunderstood the structure of your project. I assume that the unwind segue takes you to "PlayView" (UIViewController), which should trigger viewWillAppear followed by viewDidAppear .
Your understanding is correct but since I am not removing PlayView after it is initially launched, it only calls viewWillAppear / viewDidAppear once at its initial launch. Subsequent unwind segues from other views to PlayView do not call viewWillAppear / viewDidAppear in PlayView. Unless I am doing something wrong which is causing that?
@Tpos, seems a bit strange to me. ViewWill / Did should get called in 'normal' circumstances. Are you setting the navigationController delegate? Or using some container view controller setup?
My segues are modal type, perhaps thats y viewDidDisappear is not called for PlayView
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.