-1

It has been some time since I have worked on an iOS project and am struggling with what is likely a fairly basic concept to do with UINavigationControllers.

I have the following setup in my storyboard:

  • Navigation Controller
    • View 1: Login View (Root)
    • View 2: Register View
    • View 3: Verification View

My project flow requires that, after a user registers an account in the Register View, they be taken to the Verification View. My project flow also requires that I show the Verification View if the user logs in from the Root View and they have not verified their email address.

It is important that if the user presses back in the Verification View that they are always taken to the Login (Root) view, never the register view.

I have reviewed the following questions:

As well as many others and not found a good rule of thumb for situations like this. I expect the best course of action would be to return from the Register View (Pop) to the Root view and then tell the Root view to move to the Verification View using a segue but [self parentViewController] in the Register view seems to give me the UINavigationController.

My question is this: What is the correct flow to use here?

Community
  • 1
  • 1
Luke Joshua Park
  • 9,527
  • 5
  • 27
  • 44

2 Answers2

2

In the login VC add unwind method:

- (IBAction)unwindFromVerification:(UIStoryboardSegue *)segue { }

In verification VC in storyboard ctrl+drag from VC object to the Exit and select the created method. Set the identifier for that unwind segue (e.g. "UnwindFromVerification"). Then in verification VC whenever you need to unwind you just call

[self performSegueWithIdentifier:@"UnwindFromVerification" sender:nil];

Then just set hidesBackButton to YES on verification view's navigationItem and replace it with your own. Another solution would be to hide the navigation bar altogether so that user wouldn't be able to unwind by swiping right from the left edge.

Eimantas
  • 48,927
  • 17
  • 132
  • 168
  • Thanks for your answer. I was rather hoping to find a solution that could still use the automatically created navigation bar and back button that the UINavigationController creates. Does such a way exist or is your answer standard practice? – Luke Joshua Park Feb 08 '17 at 07:58
  • I am not sure how "standard" my practice is. I usually do login and signup in two different VC's that don't reside in same `UINavigationController` stack .) – Eimantas Feb 08 '17 at 08:07
1

for your Q2

It is important that if the user presses back in the Verification View that they are always taken to the Login (Root) view, never the register view.

use popToRootViewControllerAnimated:YES it Navigate to Login VC

 [self.navigationController popToRootViewControllerAnimated:YES]; 

for your another Question

My project flow also requires that I show the Verification View if the user logs in from the Root View and they have not verified their email address

Ans :

create the one bool userdefault in Login VC, check bool == false, directly navigate to Verify View, in that verify VC, if everything is fine set bool == true, else if user is new navigate to register view else navigate to main VC.

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143