Erik Kerber
Erik Kerber

Reputation: 5656

Is there a clean way to perform a segue and "forget" the last ViewController?

I'm thinking of the typical Login->Register->App flow.

If they Go

Login->Register->App

I want the underlying UINavigationController to be

Login->App

I don't want any back navigation to go back to the registration page. Likewise, it's best to clear it from memory.

Is there a simple way to do this? Or do I need to pop to the "Login" controller and then segue to the "App"?

Upvotes: 1

Views: 323

Answers (2)

rdelmar
rdelmar

Reputation: 104092

Sure, there's a simple way. Present the Register view controller modally from Login. When you dismiss it, it will be deallocated. If you want to go directly from Register to App when you do the dismissal, have the navigation controller push to App before you do the dismiss (this code is in Register view controller):

-(IBAction)dismiss:(id)sender {
    UIViewController *app = [self.storyboard instantiateViewControllerWithIdentifier:@"App"];
    [(UINavigationController *)self.presentingViewController pushViewController:app animated:NO];
    [self dismissViewControllerAnimated:YES completion:nil];
}

Upvotes: 1

prohuutuan
prohuutuan

Reputation: 230

I have implemented an app like yours.
You should design on storyboard:

1) UINavigationController (Set Initial View Controller or root) -> Login -> Register and
2) UINavigationController -> Main App

If login unsuccessful, user can register 1) UINavigationController (Set Initial View Controller) -> Login -> Register

If login successful : Forward to new UINavigationController (Login -> Main App)

//launch the main app if login successful, using Storyboad 

        UIStoryboard *mainStoryboard = self.storyboard;
        UIViewController *mainViewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"MainApp"];
        [self.navigationController pushViewController:mainViewController animated:YES];

Hope that help!

Upvotes: 0

Related Questions