How to find out when a UIView gets focus

On the iPhone, we can just use the (void) viewDidAppear:(BOOL)animated; to perform actions when the view becomes focus. In some cases, we have a modal view with another modal view on top of it, and on the iPhone, closing the top modal view will trigger viewDidAppear for the lower modal view.

This does not apply to the iPad, as the view remains β€œvisible” even if it is behind a different modal view. Is there a way to find out from inside a UIViewController when a view becomes active?

+4
source share
2 answers

Can't you just use it when the view of the modal view controller disappears? When the modal view controller receives viewWill / DidDissapear, you know that the original view is again visible.

EDIT: in viewDidDissapear modal viewcontroller add this:

 [self.parentViewController viewDidAppear:animated]; 

This will call the viewDidAppear method, as on the iPhone.

You do not need to set self.parentViewController at all, as is done for you in the presentModalViewController method (the one you use to display the modal controller)

+4
source

try checking the value of [theUIView isFirstResponder] it should be True for a view that has keyboard focus, etc.

+1
source

All Articles