views:

62

answers:

2

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?

+1  A: 

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

John Carter
Sounds like a possibility, but this isn't really an event that fires. We'd like to respond to the view becoming active rather than constantly checking if it is active.
mjdth
+1  A: 

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)

Jonathan
The problem is we'd then have to setup a link between the two modal views and tell one to tell the other to perform actions when ideally we'd like the first modal view to perform actions any time it becomes active.
mjdth
On the modally presented view controller, in the override the ViewDidDissapear:animated method and put `[self.parentViewController viewDidAppear:animated];`. That will effectively mean ViewDidAppear of the first viewcontroller is messaged/called when the 2nd modal view controller dissapears and therefore the first one appears. So you'd just put all the actions you'd like the first view controller to perform when it becomes active in ViewDidAppear like you normaaly would on iphone.
Jonathan