CodeHelp
CodeHelp

Reputation: 1328

In Modal View, DismissViewControllerAnimated After PresentViewController Not Working

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 using dismissViewControllerAnimated 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.

Upvotes: 2

Views: 15939

Answers (2)

Odrakir
Odrakir

Reputation: 4254

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];
    }];
}

Upvotes: 5

kirti Chavda
kirti Chavda

Reputation: 3015

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];
    }

Upvotes: 1

Related Questions