The Hit List Diary #16 – isBeingDismissed

When a view controller is going offscreen, it’s often good for a view controller to have a little context as to why that is. UIKit helpfully offers up the ‑isBeingDismissed method to assist with that.

So let’s say I want to end editing (so as to hide the keyboard) when a modal view is being dismissed:

Seems straightforward, but then in practice I find it doesn’t work. isBeingDismissed never returns true.

After digging around a bit, as far as I can see, isBeingDismissed only works for the presented, root view controller, not any children. And of course my view controller in this case is embedded inside of several other controllers, the topmost being the one that gets presented.

There’s no particularly nice way to find the root of a view controller hierarchy it seems to me, so I’ve ended up with this cludge:

(presentingViewController works from anywhere in the hierarchy, so I effectively get to jump back and forth to find the true presented view)

This seems quite a shame to me, so I’ve filed rdar://19060030 in the hopes that .isBeingDismissed will be improved some day to work from anywhere within a stack.

© Mike Abdullah 2007-2015