How to handle UINavigationControllers and UITabBarControllers iOS 6.1

I need a good explanation of how I can handle UINavigationControllers and UITabBarControllers on iOS6.1 with StoryBoards.

  • When I download my application (1st ViewController), I need (FB login = success) to automatically jump using segues to the second ViewController. Here I think that I can not use the UINavigationController as root, Apple HIG does not like it. image 1
  • I need a UITabBarController that connects to 3 UICollectionViewControllers (one tab for each). Should I put UITabBarController as root? If so, how can I handle other Viewontrollers between them? Like this: Image 2
  • I need a custom BarButtonItem (for example, โ€œDelete Allโ€, which you can see in image 2) on each CollectionViewController, do I need to use a UINavigationController for each of them?
0
source share
1 answer

Suppose you are happy to use unwinding segues (unless there are many ways to do without).

1 When I load my application (1st ViewController), I need (FB login = success) to automatically jump using segues to the second ViewController. Here I think that I can not use the UINavigationController, for example root, apple HIG do not like.

You are the first VC (let's call it loginVC).
- DO NOT be contained in the navigation controller.
- must be installed as initialViewController application

Second VC (let's call it startVC)
- MUST be included in the navigation controller
- in this navigation controller identification manager, assign storyboardID: @"InitialNavController"

In the App Delegate application, let it have the loggedIn BOOL property:

 @property (nonatomic, assign) BOOL loggedIn; 

Now in your LogInViewController ...

In viewDidAppear check if we are already logged in, if so, go to startVC immediately:

 - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; if ([(AppDelegate*)[[UIApplication sharedApplication] delegate] loggedIn]) { UINavigationController* navController = [[self storyboard] instantiateViewControllerWithIdentifier:@"InitialNavController"]; [self presentViewController:navController animated:NO completion:nil]; } } 

It is important that this is placed in viewDidAppear, and not (for example) in viewDidLoad - segue will not work if the original view is not correctly initialized on the screen either.

Make Unwind Segue (and declare it in loginVC @interface ) ... loginVC will be the target VC if users log out.

 - (IBAction)unwindOnLogout:(UIStoryboardSegue *)segue { [(AppDelegate*)[[UIApplication sharedApplication] delegate] setLoggedIn:NO]; } 

(fixed - this line was deleted:
[[self presentedViewController] dismissViewControllerAnimated:YES completion:nil];
we do not need to be fired, as segue has already done this behind the scenes. This is redundant and logs an error message)

In other viewControllers, if it suits you, you can make the "Exit" button. CTRL-drag from this button to the 'exit' symbol at the bottom of the ViewController in the storyboard, and you can select this segment as the unwind.

2 I need a UITabBarController that connects to 3 UICollectionViewControllers (one tab for each). Should I install UITabBarController as root? If so, how can I handle other Viewontrollers between them? Like this:

I think you are trying to figure out how the tabBarController relates to the NavigationController in the previous viewController (startVC). The answer is that it shouldn't - you really don't want to embed the Tab Bar VC in the previous Nav Controller, as this will create strange situations for the child viewControllers for the tab bar.

Navigation from startVC to tabBarVC should go through the modal segment, and not click.

You can do another Segue rollup in startVC to make it easier to return from your viewBarController viewControllers:

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

(fixed - deleted this line: [[self presentedViewController] dismissViewControllerAnimated:YES completion:nil]; this method does not need any content to complete the dismissal)

3 I need a custom BarButtonItem (for example, โ€œDelete Allโ€, which you can see in image 2) on each CollectionViewController, do I need to use a UINavigationController for each of them?

By default, you will not get the navigation bar in your tabBarVC.

You can provide one of two ways.
- embed each child of the viewController in its own navigation controller; - manually drag the navigation bar into EVERY child scene of the viewController.

Curiously, this really depends on whether you want to use navigation for other ViewControllers.

You can then add barButtonItem left or right to connect to the initial VC U-turn (CTRL-drag to the "exit" symbol).

enter image description here

+3
source

All Articles