我的应用程序中有一个计时器。如果计时器达到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
}

最佳答案

您可以执行以下操作:

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

关于ios - 在展示另一个时关闭ViewController,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31168767/

10-12 01:29