简体   繁体   中英

Is this a good way to manage my view controller stack?

I have a lot of modal view controllers for my game. And so I need a way to pop my view controllers off the stack so that I don't have too many view controllers on the stack.

So say I have vc 1 that segues to vc 2, that segues to vc3, and vc3 segues to vc1.

When it segues back to vc 1, should I call,

[self.navigationController popToRootViewControllerAnimated:YES]; ?

Also, in order to replay my game, all I did was have a replay button that segues to its own vc. And I was told this was a bad idea, so is it ok if whenever I hit that replay button I call [self.navigationController popViewControllerAnimated:YES]; ?

The reason I want it to segue to its own vc is because I want the cool cross dissolve animation that happens when you segue modally.

If I do all this will it work without problems?

You are doing everything right for everything but the self -> self transitions.

You should just have an animation.

For example:

 - (void)reset
{
    [self resetInternalModelState];

    [self animateWithDuration:duration animations:^{
        // Logic to dissolve your view.
    }];

    [self reloadModelData];
}

If you imagine that you have a method that resets the state, and a method that reloads the views based on your internal model data, this will do exactly what you want, without abusing the animation freebies you get from view controller transitions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM