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];
}
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With