How would you implement state restoration for a modal or "presented" view controller?

Let's say for example that I have ViewController and SecondViewController. ViewController has a single button. When you click the button, it presents SecondViewController (using a modal segue).

有帮助吗?

解决方案

The problem is that you recreating your modalVC before you presenting it.

EX: What you're doing

-(IBAction)presentModalVC:(id *)sender{
 ModalVC *modalVC = [self.storyboard instantiateViewControllerWithIdentifier:@"modal"];    
 [self presentViewController:modalVC animated:YES completion:nil];
}

What you need to do:

create property of your modalVC and initialize it in viewDidLoad method

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top