Modal UINavigationController, iOS 13 dismiss detection, & UIAdaptivePresentationControllerDelegate

Just a quick tip for those who are trying to set the presentation controller delegate to capture presentationControllerDidAttemptToDismiss from UIAdaptivePresentationControllerDelegate or any of the like – if your view is being presented via a UINavigationController, the presentation controller that will receive the feedback will actually be on the navigation controller itself.

 

So, instead of:

func viewDidLoad() { 
    self.presentationController?.delegate = self
}

you’ll need to dive a layer deeper:

func viewDidLoad() { 
    self.navigationController?.presentationController?.delegate = self
}

 

Not too fond of this behavior since it makes things a little messier and especially given UINavigationController is smart enough to receive isModalInPresentation from any other controllers in the stack (wouldn’t be better to forward events to the top most controller?)

Anyway, speculation aside — it took me awhile to put two and two together. Good luck out there!

I am Dan Griffin and you can find me on Mastodon

The Blog

Base & Elevated System (and Grouped!) Background Colors

In iOS 13, Apple introduced a slew of new colors that are also dynamic – meaning they will adjust between light and dark modes (and other scenarios, such as high contrast). Of the new colors, the various background colors are pretty pecular: iOS defines two sets of background colors—system and grouped—each of which contains primary,…

iOS iOS 13

Always Taking Inquiries

At the moment I am not taking on many new projects, but am still available for inquiry or questions.

Reach Out To Dan