2

I have a little problem on dismissing a VC.

My Project has 2 Viewcontroller. Viewcontroller A and Viewcontroller B.

Viewcontroller A has a button. If i press this button, the second ViewController B pops up.

The second ViewController (B) has a button. If i click this button this action will begin:

    @IBAction func dismiss(_ sender: UIBarButtonItem) {

    self.presentedViewController?.dismiss(animated: true, completion: nil)

}

This action should actually dismiss the Viewcontroller and should show me the Viewcontroller A again.

But nothing happens if i press this button.

Did I forgot something?

iOS Koray
  • 41
  • 1
  • 9

1 Answers1

10

Should be:

@IBAction func dismiss(_ sender: UIBarButtonItem) {
    self.dismiss(animated: true, completion: nil)
}

presentedViewController of Viewcontroller B is nil, that is why nothing happens. presentedViewController of Viewcontroller A is your Viewcontroller B

janusfidel
  • 8,036
  • 4
  • 30
  • 53