Egor Iskrenkov
Egor Iskrenkov

Reputation: 443

Two ViewControllers unwind issue

I have three View Controllers and want to go back from the third to the first on button click. I do the following:

  1. Add the target to my button: doneButton.addTarget(self, action: #selector(ThirdViewController.doneButtonPressed(_:)), for: .touchUpInside)
  2. Create the action in the first controller: @IBAction func unwindFromNewSubscription(segue: UIStoryboardSegue) { }
  3. Create the unwind segue linking it to the action from #2 in the storyboard and set the "chageFromNewToMain" identifier
  4. Create the action for my button in the third controller: @IBAction func doneButtonPressed(_ sender:UIButton!) { print("DONE BUTTON PRESSED") performSegue(withIdentifier: "changeFromNewToMain", sender: self) }

And it works, BUT when I tap the button in V3 it instantly disappears and I see the animation: V2 slides down, so finally I can see the V1. But I want to animate the V3 to slide down instead of disappearing to see V1 after that. Any ideas how to fix that?

(V1, V2, V3 - View Controller 1, 2, 3)

Upvotes: 1

Views: 38

Answers (1)

iyuna
iyuna

Reputation: 1797

Try to use presentingViewController?.dismiss(animated: true, completion: nil) inside your @IBAction func doneButtonPressed(_ sender:UIButton!) action instead of calling performSegue(withIdentifier: "changeFromNewToMain", sender: self).

Upvotes: 1

Related Questions