I have three view controllers
- ViewControllerA
- ViewControllerB
- ViewControllerC
This is a scenario I'm trying to solve
- ViewControllerA pushes ViewControllerB on navigation hierarchy
ViewControllerB presents ViewControllerC as modal, with close delegate
ViewControllerC close button is pressed, close delegate is sent and ViewControllerC is dismissed
ViewControllerB receives the close delegate, and tries to dismiss itself so ViewControllerA is displayed
For some reason ViewControllerB is not being dismissed. If I press the cancel button in ViewControllerB then it can be dismissed.
Why can’t consecutive dismiss’ be done?
ViewControllerC
@IBAction func closeClick(sender: AnyObject) {
self.closeDelegate?.didClose()
self.dismissViewControllerAnimated(true, completion: nil)
}
ViewControllerB
func didClose() {
print("did close") // gets called
self.dismissViewControllerAnimated(false, completion: nil) // no dismiss
//self.navigationController?.popViewControllerAnimated(false)
}
@IBAction func cancelClick(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil) // works
}
didClose
delegate, view controller C hasn't yet dismissed itself. If you are using storyboard then define an unwind segue to view controller A and trigger that from view controller c, otherwise I would suggest that you try calling thedidClose
delegate after the dismiss or have view controller b dismiss C in the delegate method – Paulw11