Reputation: 219
I have a timer in my app. If the timer reaches 0, the user is brought to a failure page. When that happens, the previous ViewController was not dismissed, leading to more memory being taken up.
I want the previous ViewController to be dismissed if the Failure Page is presented.
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
}
Upvotes: 0
Views: 171
Reputation: 650
You can do something like this:
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]
}];
}
Upvotes: 2