thomasdao
thomasdao

Reputation: 982

Should we avoid push segue loop between two view?

Well, to some of you this question may sounds ridiculous but I'm discussing with my teammates about the design of an ios app and I need your opinion about it.

The old design which I disagree is as following

As you can see, there is a segue loop between ViewController A and B and I think we should never let it happens. I would prefer go from B to A by "Back" button in navigation bar.

How serious is the PUSH segue loop in design? Is it acceptable in some cases? Where can I see the recommended good design by apple (if there are any?)

EDIT: I try "pop before push" solution by nfarshchi but it do not work.This is how I did: 1) I cannot create segue from VC A to VC B and segue from VC B to VC A at the same time. It seems that storyboard prevents it from happening 2) Thus I create one segue whose identifier is "gotoB" from Button "Go to B" in VC A to VC B and one segue whose identifier is "gotoA" from Button "Go to A" in VC B to VC A.

So the Storyboard would looks like this:

VC X ---Push---> VC A <----Push----> VC B (The reason I need ViewController X is explained later) 3) In VC A I have this:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSLog(@"Prepage for segue go to B") ;
    if ([[segue identifier] isEqualToString:@"gotoB"] ) {
        [self.navigationController popViewControllerAnimated:NO];

    }
}

I need VC X because I cannot pop a ViewController from Stack if there is only one ViewController in there.

Now it seems right, but when I clicked "Go to B", it went to VC X instead. It was clearly that the above popViewControllerAnimated: has poped VC A, and that's all, the segue to VC B was no longer fired. The result was the VC B was not pushed into Stack as expected.

Thus I think it is unfeasible to implement nfarshchi's solution

Upvotes: 5

Views: 1004

Answers (2)

Mike Weller
Mike Weller

Reputation: 45598

The push/pop transition should only be used if the virtual 2D space that the transition creates is realistic. If the user sees 10 push transitions in a row, it is going to feel like they are going deeper and deeper into a hierarchy and it can lead confusion and a bad mental model, especially if in reality you are just moving between two view controllers.

Using the back button would be a better solution, or you can make your own custom transition which makes it clearer to the user what is going on. Perhaps a flipside transition would also be appropriate.

Upvotes: 1

nfarshchi
nfarshchi

Reputation: 1000

You can do that but consider when you push out a UIViewController and again push it in you will call a lot of methods to re design it. if you want to move over them a lot it is better to use UINavigationController. in this case you only make them once and you can navigate between them easily. this will use less system resources

Upvotes: 3

Related Questions