I have a main menu that leads to a view where you play a game. From the view where you play the game you can click a button to return to the main menu, I'm using unwindSegue for this. Is there a way to now click on the same "play game" button from the main menu, replace the view, and keep the game state as it was before unwindSegue was called or will I have to store the data reload in a new view?

有帮助吗?

解决方案

Yes, you can do that, but not with a segue, since they always instantiate new controllers (except for the unwind). So, you can create a property for your game view controller in the main menu, and only instantiate it if it doesn't already exist, then push it with pushViewController:animated:. Something like this,

-(IBAction)gotToGameView:(id)sender {
    if (! self.game) {
        self.game = [self.storyboard instantiateViewControllerWithIdentifier:@"Game"];
    }
    [self.navigationController pushViewController:game animated:YES];
}

其他提示

You should store the data that is needed for recreating the view. Then, when the user enters the same screen again you can recreate a view with your saved data.

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