1

I did extensive googling on the matter, perhaps I am unable to find the right keywords, so no luck identifying a solution. Perhaps someone here may help.

I have 3 Viewcontrollers - Master, Detail and TaskEditViewController.

I am posting local notifications that fire up a method on Detail VC, which is supposed to unwind to Master and then fire up a method that would segue to TaskEditViewController.

What happens is that first I get the segue animated from Detail to TaskEditViewController (they have no segue on storyboard), and after that the unwind happens and goes to Master.

Here's my code on Detail VC (the one receiving the notification):

func editFromNotification(notification: NSNotification) {
    print("Add New Task Screen received")
    if let notifId = notification.object!["notifId"] as? String {

        taskIdToSend = notifId

        selectedTask = getTaskForSelectedId(notifId)

        self.performSegueWithIdentifier("sendNotificationToMaster", sender: nil)   
    }   
}

And here's the method that gets fired up from the unwind segue on Master VC:

@IBAction func unwindAndProcessNotification(segue:UIStoryboardSegue) {
    if(segue.sourceViewController .isKindOfClass(Detail)) {
        let viewSource:Detail = segue.sourceViewController as! Detail
        let receivedTaskId = viewSource.taskIdToSend
        print("Task sent to open is: \(receivedTaskId)")
        selectedTask = getTaskForSelectedId(receivedTaskId)
        performSegueWithIdentifier("showEditScreen", sender: nil)
    }
}

If anyone can shed some light on the matter, the behaviour I get is a complete mystery for me...

ddikov
  • 43
  • 6
  • 1
    The unwind method triggers before the unwind segue has completed, so you are triggering the edit segue before the unwind to master has occurred so you see the edit screen and then the master screen as the unwind completes. You need the master to trigger the segue in a method such as `viewWillAppear`. You can set a flag on the master VC in the unwind method to indicate that it should do this – Paulw11 Feb 10 '16 at 21:26
  • hey, thanks, that totally worked, do you wanna post it as an answer, so I can select it as resolved? – ddikov Feb 10 '16 at 22:21

1 Answers1

2

The unwind method triggers before the unwind segue has completed, so you are triggering the edit segue before the unwind to master has occurred.

As a result, you see the edit screen and then the master screen as the unwind completes.

You need the master to trigger the segue in a method such as viewWillAppear. You can set a flag on the master VC in the unwind method to indicate that it should do this

Paulw11
  • 108,386
  • 14
  • 159
  • 186