2

I have a secondary ViewController that appears programmatically via a Storyboard segue:

func actioncall ()
{
    performSegue(withIdentifier: "showIgnoreVC", sender: self)

}

)

This function is part of the main ViewController, and is called via an NSNotification from the AppDelegate, which in turn is triggered by a Menu Item click.

However, even though the segue is connected to the main ViewController, the following code does not dismiss the secondary view:

@IBAction func dismiss(_ sender: Any)
{
    print("Hello?  Gonna close?")

    self.presenting?.dismissViewController(self)
}

There are no errors, the function is called upon the correct Dismiss button click, but the secondary view does not dismiss. I have tried every variation of dismissViewController to no avail.

When I use a button on the Main view to activate the same segue, everything works as it is supposed to. I simply do not wish to clutter up the main View with a bunch of buttons.

Any ideas are appreciated, thank you very much.

Craig Smith
  • 1,063
  • 2
  • 11
  • 21
  • When this line `self.presenting?.dismissViewController(self)` executes, what is the value of `self.presenting`? – Dave Weston Feb 18 '17 at 22:43
  • @DaveWeston, good question. Using `let x = self.presenting! as NSViewController`, the app crashes with **fatal error: unexpectedly found nil while unwrapping an Optional value**. Apparently there is no viewController presenting. – Craig Smith Feb 19 '17 at 01:55

1 Answers1

0

dismissViewController works only for view controllers, that were presented modally (using Present Modally Segue) As said in the answer to this SO question, you should dismiss view controllers, presented by Show Segue, like this:

navigationController?.popViewController(animated: true)
dismiss(animated: true, completion: nil)
Community
  • 1
  • 1
Artem Misesin
  • 373
  • 3
  • 13
  • dismissViewController works for view controllers presented as a sheet, and show as well. In this project, there is no navigationController. Thank you for your input anyway. – Craig Smith Feb 19 '17 at 01:44