Reputation: 307
How can I call viewwillappear
after dismissing modalviewcontroller
?
Any idea please because after dismissing my viewwillappear
didn't get called :
presenting my viewcontroller modally : //firsviewcontroller :
-(IBAction)AddActivity:(id)sender{
CreateActivity *addViewController = [[CreateActivity alloc] initWithNibName:@"CreateActivity" bundle:nil];
addViewController.delegate = self;
addViewController.modalPresentationStyle = UIModalPresentationFormSheet;
addViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:addViewController animated:YES];
addViewController.view.superview.frame = CGRectMake(50, 260, 680, 624);
}
//secondvioewcontroller : I create An alertview to dismiss this modalview , but the viewwillapear didn't get called:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0){
if ([self respondsToSelector:@selector(presentingViewController)]){
[self.presentingViewController dismissModalViewControllerAnimated:YES];
}
else {
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
}
}
Upvotes: 26
Views: 23939
Reputation: 104082
Since you're presenting the modal view controller as a form sheet, the presenting controller's view never disappears, so viewWillAppear:
is not called after the dismissal. If you want the presenting view controller to handle something after the dismissal, call a delegate method in the modal controller's viewDidDisappear:
method. You've already set the delegate, so I presume you already have a delegate protocol in CreateActivity
.
By the way, you should use the non-deprecated methods to present and dismiss your modal view controller.
Upvotes: 12
Reputation: 39512
presentModalViewController:animated:
/ dismissModalViewControllerAnimated:
are deprecated. Use presentViewController:animated:completion:
/ dismissViewControllerAnimated:completion:
instead.
You can use the completion block to execute any code post dismisal:
- (void) alertView: (UIAlertView *) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
{
if (buttonIndex == 0)
{
MyCustomViewController* mcvc = (MyCustomViewController*)self.presentingViewController;
[self dismissViewControllerAnimated: YES completion: ^{
// call your completion method:
[mcvc someCustomDoneMethod];
}];
}
}
Better yet, if you're using a storyboard then you can implement an unwind segue and trigger your completion code in the unwind callback method.
Upvotes: 13