In Modal View, DismissViewControllerAnimated After PresentViewController Not Working
15,924
Solution 1
It's not clear what you are trying to do. I give you two options:
Presenting ModalView2 and then dismissing ModalView2 (makes no sense to me, but that's what I can read in your question)
- (void) buttonAction: (UIButton*) sender {
ModalView* modalView2 = [[ModalView alloc] init];
[self presentViewController:modalView2 animated:YES completion:^{
[modalView2 dismissViewControllerAnimated:YES completion:nil];
}];
}
Presenting ModalView2 and dismissing ModalView1:
- (void) buttonAction: (UIButton*) sender {
ModalView* modalView2 = [[ModalView alloc] init];
UIViewController* presentingViewController = self.presentingViewController;
[self dismissViewControllerAnimated:YES completion:^{
[presentingViewController presentViewController:modalView2 animated:YES completion:nil];
}];
}
Solution 2
at time present and dismiss not call so give some time
try this it working me
- (void) buttonAction: (UIButton*) sender
{
[self performSelector:@selector(call) withObject:nil afterDelay:.4];
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)call
{
ModalView *ModalView2 = [[ModalView alloc] init];
[self presentViewController:ModalView2 animated:YES completion:nil];
}
Author by
CodeHelp
Updated on June 05, 2022Comments
-
CodeHelp almost 2 years
I come across this issue while doing some testing. I have presented a Modal view, called ModalView1. In ModalView1, when a button is pressed, another Modal view, called ModalView2 would be presented using
presentViewController
. Then I tried dismissing ModalView2 usingdismissViewControllerAnimated
but it is not working.
Here is the code fragment in button action- (void) buttonAction: (UIButton*) sender { ModalView *ModalView2 = [[ModalView alloc] init]; [self presentViewController:ModalView2 animated:YES completion:nil]; [self dismissViewControllerAnimated:YES completion:nil]; }
Any help would be much appreciated. Thank you.