在呈现另一个时解除ViewController

时间:2015-07-01 18:16:45

标签: ios objective-c xcode

我的应用中有一个计时器。如果计时器达到0,则用户将进入故障页面。当发生这种情况时,之前的ViewController没有被解雇,导致更多的内存被占用。

如果显示失败页面,我希望解除之前的ViewController。

    if (self.countdownTimer == 0) {

    FailurePage *failurePage = [[FailurePage alloc] init];
    [self presentViewController:failurePage animated:YES completion:NULL];

//I want to dismiss the current ViewController when the Failure Page is presented
}

1 个答案:

答案 0 :(得分:2)

您可以这样做:

    if (self.countdownTimer == 0) {

        UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
        FailurePage *failurePage = (FailurePage*)[mainStoryboard instantiateViewControllerWithIdentifier: @"<Controller ID>"];

        [self presentViewController:failurePage animated:YES completion:^{
            [self.parentViewController dismissViewControllerAnimated:NO completion:nil]
         }];
    }