Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell when a UIView gains focus

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

This is not the case for the iPad, as the view stays "visible" even though it's behind another modal view. Is there any way to tell from within a UIViewController when the view itself becomes the active view?

like image 568
mjdth Avatar asked Oct 22 '10 18:10

mjdth


2 Answers

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

EDIT: in the viewDidDissapear of the modal viewcontroller add this:

[self.parentViewController viewDidAppear:animated];

This will make the viewDidAppear method be called as it is on the iPhone.

You don't need to set self.parentViewController at all, as it is done for you in the presentModalViewController method (the one your use to display the modal view controller)

like image 135
Jonathan. Avatar answered Oct 09 '22 05:10

Jonathan.


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

like image 31
John Carter Avatar answered Oct 09 '22 04:10

John Carter