Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

  • We have ViewControllerA which contains Button "Go To B". The button has a PUSH segue to go to B.
  • We have ViewControllerB which contains Button "Go To A".The button has a PUSH segue to go to A.
  • We have to travel between the 2 ViewController a lot.

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

like image 507
thomasdao Avatar asked Oct 08 '22 10:10

thomasdao


1 Answers

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

like image 102
nfarshchi Avatar answered Oct 13 '22 10:10

nfarshchi