I have the following view hierarchy: view controller A -> popover segue -> navigation controller -> view controller B -> UIImagePickerController
Within the View controller B popover, I use the following code to present the UIImagePickerController:
picker = UIImagePickerController()
picker!.allowsEditing = false
picker!.sourceType = .photoLibrary
picker!.mediaTypes = [kUTTypeMovie as String]
picker!.isModalInPopover = true
picker!.modalPresentationStyle = .currentContext
picker!.delegate = self
present(photoLibraryPickerController!, animated: true, completion: nil)
When the user taps "cancel", I want to dismiss both the image picker and view controller B popovers, and go straight back to view controller A. Here is my code to do this:
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
picker!.dismiss(animated: false, completion: nil)
dismiss(animated: false, completion: nil)
}
This effectively dismisses both the image picker and view controller B, but there is a brief delay after the image picker is dismissed. So you can see view controller B on the screen for a moment before it is then dismissed.
How can I dismiss both view controllers simultaneously to avoid this flashing?