First of all, I know there are dozens of questions with the same error message as mine. However, the context of my problem is totally different, so I wasn't able to solve it with the previous StackOverflow questions.
I created a custom Segue and everything worked fine yesterday. Today, I have modified my app even further and no all of a sudden my app doesn't work anymore.
My app crashes with the following eror message
Presenting view controllers on detached view controllers is discouraged - AppName.MainNavigationController: 0x7ff19f054a00.
The crashing point is: sourceViewController.present(destinationViewController, animated: false, completion: nil)
After modifying my app today, I have Following controller hierarchy
VC: A -> UINAVIGATION CONTROLLER: B - ROOT CONTROLLER OF NAVIGATIONCONTROLLER: C -> * WITH THIS CUSTOM SEGUE * VC: D
-> : represents a segue. This segue is made from C, the root controller of the navigation Controller
It's really strange because everything was working perfectly and now I get this crash.
This is the perform method of my custom segue:
override func perform() {
//.... custom segue animation......
//.....
UIView.animate(withDuration: DURATION, animations: {
// Some more animations
self.bubble.transform = CGAffineTransform.identity
destinationView?.transform = CGAffineTransform.identity
destinationView?.alpha = 1
destinationView?.center = sourceCenter!
destinationView?.layer.cornerRadius = 1
}, completion: { (_) in
self.bubble.isHidden = true
destinationView?.clipsToBounds = defaultClipsToBoundsSettings!
//finally showing it
DispatchQueue.main.async
{
//********* THIS IS THE CRASH POINT
sourceViewController.present(destinationViewController, animated: false, completion: nil)
}
})
}
Here I am performing the segue from my button action method:
castedRootController.performSegue(withIdentifier: "ViewShare", sender: nil)
The segue should be between VC A and navigationController B , as the VC C is considered a rootVC for the navigation , Also during the segue VC A is shown no the navigationController