在模态视图中,在PresentViewController不工作之后DismissViewControllerAnimated

时间:2013-10-12 04:06:37

标签: ios objective-c uiviewcontroller

我在做一些测试时遇到过这个问题。我提出了一个名为ModalView1的模态视图。在ModalView1中,当按下某个按钮时,将使用presentViewController显示另一个名为ModalView2的模态视图。然后我尝试使用dismissViewControllerAnimated解雇ModalView2,但它无法正常工作。
这是按钮操作中的代码片段

- (void) buttonAction: (UIButton*) sender
{
    ModalView *ModalView2 = [[ModalView alloc] init];
    [self presentViewController:ModalView2 animated:YES completion:nil];
    [self dismissViewControllerAnimated:YES completion:nil];
}

非常感谢任何帮助。谢谢。

2 个答案:

答案 0 :(得分:5)

目前尚不清楚你要做什么。我给你两个选择:

呈现ModalView2然后解雇ModalView2(对我没用,但这就是我在你的问题中可以阅读的内容)

- (void) buttonAction: (UIButton*) sender {
    ModalView* modalView2 = [[ModalView alloc] init];
    [self presentViewController:modalView2 animated:YES completion:^{
        [modalView2 dismissViewControllerAnimated:YES completion:nil];
    }];
}

演示ModalView2并解散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];
    }];
}

答案 1 :(得分:1)

在现在的时候,不要打电话给所以给点时间

试试这个让我工作

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