mani_007
mani_007

Reputation: 602

presentViewController from TabBarController to outside

Here is my main StoryBoard:

Storyboard

As you can see there is a main TabBarController, but in Order to see the TabBarController user has to login first in (LoginViewController which is outside of main TabBarController this is the code in viewDidLoad of all my controllers in TabBar:

    if ( ![Client isLoggedIn] ) {
         UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:Nil];
         UIViewController* loginView = [storyboard instantiateViewControllerWithIdentifier:@"LoginScene"];
         [self.navigationController presentViewController:loginView animated:YES completion:nil];
         return;
    }

but sometimes(!) this doesn't work at all and application hangs (and when it happens even uninstalling the application doesn't help)

What is the correct way to redirect user from TabBarController to another ViewController (LoginViewController) in this case, which is not a child of TabBarController?

Upvotes: 1

Views: 3653

Answers (2)

simalone
simalone

Reputation: 2768

Just try replace

[self.navigationController presentViewController:loginView animated:YES completion:nil];

with

[self presentViewController:loginView animated:YES completion:nil];

Upvotes: 0

lootsch
lootsch

Reputation: 1865

You could connect your separate NavigationViewController as a manual modal segue to the TabbarController. Set an identifier to the segue, then you can use this code:

if ( ![Client isLoggedIn] ) {
    [self performSegueWithIdentifier:@"MyModalSegue" sender:self];
}

This should work properly. In addition, you get the modal animation for free.

Upvotes: 2

Related Questions