I have a modal presentation for a card that uses a custom presentation controller, which works fine. I now need to use a presentation controller for another popup, but the difficulty is that it needs to be different. I ran into multiple problems trying to overcome this.
First problem: I can obviously not have two same extensions to my view controller, meaning that I can only reference one UIPresentationController File as far as I know. I would, however, ideally need a second UIPresentationController to manage the second Presentation.
Second Problem: Since I could not have a second Extention, I tried using an if statement inside the Extention as such:
extension ThirdViewControllerPassenger: UIViewControllerTransitioningDelegate {
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
if something == something {
PresentationController(presentedViewController: presented, presenting: presenting)
} else {
PresentationController2(presentedViewController: presented, presenting: presenting)
}
}
}
That did not work, I am guessing because I can not change the syntax of the extention. The error was a missing return.
Third problem: My last Idea was to use a user defaults key to save a state and then check the state for each function inside my UIPresentationController. I would for example set defaults.set("showTripOverview", forKey: "presentationStyle")
and then split my UIPResentationController Functions into two parts, one if presentationStyle is "ShowTripOverview" and one if its not. The Idea worked out well, the code compiled and it seemed to work. But it wasn't for long when I noticed that all my defaults I set in my main ViewController (that must have run before calling the UIPresentationController!!) were set to nil. So all my if calls were going straight to the else, which was not what I wanted...
Can anyone explain to me how I can fix one of the three issues? I just need to be able to use a second UIPresentationController somehow to tweak the animation ect. for the second presentation. I wouldn't think that it's a strange thing to do since many apps use different ways of presenting things. Could not find anything on the web though...