Reputation: 35
I have two views with their controllers.
The application start with the FirstViewController
.
Then with a button I open the SecondViewController
.
With other button I dismiss the SecondViewController
to return to FirstViewController
.
Is there any way to detect that in FirstViewController
that it has recovered focus?
EDIT: Ok I look the answers and I use viewWillAppear
but don't work if I use a UIModalPresentationFormSheet
.
-(IBAction)openSecondView{
SecondViewController *screen = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
screen.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:screen animated:YES];
[screen release];
}
And close this view with close button.
viewWillAppear
never called.
Upvotes: 0
Views: 149
Reputation: 1
inside the viewWillAppear
of the FirstViewController
- (void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
NSLog(@"view 1 focused");
}
Upvotes: 0
Reputation: 5681
Depends how you are setting up the first view controller. Encapsulate it within UINavigationViewController (and if you do not want the navigation bar, you can always set it to hidden ( [self.navigationController.navigationBar setHidden:YES]
). ViewWillAppear
will work then.
Upvotes: 0
Reputation: 6413
implementation of the viewWillAppear: callback will work only if you use navigation controller or tabbarcontroller for displaying another controller + with such approach you will need to check somehow if this is only the first appearance of the view, or was called by any other reason;
using a delegate, as described by Gomathi above is a much better option!
Upvotes: 0
Reputation: 17478
Add a delegate (Protocol) method. Call the delegate method just before dismissing the SecondViewController.
For more info on delegate, see delegate
Upvotes: 1
Reputation: 3547
implement UIViewController's viewWillAppear method
- (void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
}
Upvotes: 2