如何处理 UINavigationControllers 和 UITabBarControllers iOS 6.1 [英] How to handle UINavigationControllers and UITabBarControllers iOS 6.1

查看:22
本文介绍了如何处理 UINavigationControllers 和 UITabBarControllers iOS 6.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  1. When I load my app (1st ViewController) I need if (FB login = success) it jumps with segues to the 2nd ViewController automatically. Here I think I can't use a UINavigationController like root, apple's HIG don't like it.
  2. I need a UITabBarController that connects to 3 UICollectionViewControllers (one tab for each one). I have to put the UITabBarController like root? If yes, how can I handle the others Viewontrollers between them? Like this:
  3. I need a custom BarButtonItem (like the "Delete All" that you can see on the image 2) on each CollectionViewController, I need to use a UINavigationController for each one?

解决方案

Let's assume you are happy to use unwind segues (if not there are many ways to do without).

1 When I load my app (1st ViewController) I need if (FB login = success) it jumps with segues to the 2nd ViewController automatically. Here I think I can't use a UINavigationController like root, apple's HIG don't like it.

You 1st VC (lets call it the loginVC)..
- should NOT be contained in the Navigation Controller.
- should be set as the application's initialViewController

Your 2nd VC (lets call it your startVC)
- SHOULD be contained in the Navigation Controller
- in that Navigation Controller's Identity Inspector, assign a storyboardID: @"InitialNavController"

In your App Delegate, let's have a loggedIn BOOL property:

@property (nonatomic, assign) BOOL loggedIn;

Now, in your LogInViewController...

In viewDidAppear check to see if we are already logged in, if so, navigate immediately to your startVC:

- (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's important that this is placed in viewDidAppear, not (for example) in viewDidLoad - the segue won't work unless the initial view is properly initialised and onscreen.

Make an unwind Segue (and declare it in loginVC's @interface) … loginVC will be the destination VC if users log out.

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

}

(corrected - removed this line:
[[self presentedViewController] dismissViewControllerAnimated:YES completion:nil];
we don't need to dismiss as the segue has already done that behind the scenes. This is redundant and logs an error message)

In other viewControllers, whereever appropriate you can make a 'logout' button. CTRL-drag from that button to the 'exit' symbol at the bottom of the ViewController in the storyboard, and you will be able to select this segue as the unwind segue.

2 I need a UITabBarController that connects to 3 UICollectionViewControllers (one tab for each one). I have to put the UITabBarController like root? If yes, how can I handle the others Viewontrollers between them? Like this:

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

The navigation from startVC to the tabBarVC should be via a modal segue, NOT a push segue.

You can make another unwind Segue in startVC to facilitate return from your tabBarController's viewControllers:

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

}

(corrected - removed this line:   [[self presentedViewController] dismissViewControllerAnimated:YES completion:nil];   this method doesn't need any content to perform the dismissing)

3 I need a custom BarButtonItem (like the "Delete All" that you can see on the image 2) on each CollectionViewController, I need to use a UINavigationController for each one?

You won't get a Navigation bar in your tabBarVC by default.

You can provide one in two ways
- embed each child viewController in it's own Navigation Controller;
- manually drag a navigation bar to EACH child viewController's scene.

Either is fine, it really just depends whether you will want navigation to other ViewControllers.

You can then add a barButtonItem on the left or right to connect up to the initialVC's unwind segue (CTRL-drag to the 'exit' symbol).

这篇关于如何处理 UINavigationControllers 和 UITabBarControllers iOS 6.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆