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

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

问题描述

我需要一个很好的解释如何使用StoryBoards处理iOS6.1上的 UINavigationControllers UITabBarControllers

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


  1. 当我加载我的应用程序(第一个ViewController)时,我需要if(FB login = success)它会自动跳转到第二个ViewController的segues。在这里我想我不能像root一样使用 UINavigationController ,苹果的HIG不喜欢它。

  2. 我需要 UITabBarController 连接到3 UICollectionViewControllers (每个选项卡一个选项卡)。我必须把 UITabBarController 像root一样?如果是,我如何处理它们之间的其他Viewontrollers?像这样:

  3. 我需要定制BarButtonItem(就像你在图像2上看到的全部删除)在每个CollectionViewController上,我需要为每一个使用 UINavigationController 吗?

  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?


推荐答案

让我们假设你很乐意使用unwind segues(如果没有很多方法可以不用)。

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


1当我加载我的应用程序(第一个ViewController)时,我需要if(FB login = success)它会自动跳转到第二个ViewController的segues。在这里我想我不能像root那样使用UINavigationController,苹果的HIG不喜欢它。

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.

你是第一个VC(让我们称之为loginVC)..

- 不应该包含在导航中控制器。

- 应设置为应用程序的initialViewController

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

你的第二个VC(让我们称之为你的startVC)

- 应该包含在导航控制器

中 - 在该导航控制器的Identity Inspector中,分配一个storyboardID: @InitialNavController

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"

在你的App Delegate中,我们有一个 loggedIn BOOL属性:

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

@property (nonatomic, assign) BOOL loggedIn;

现在,在你的LogInViewController ...

Now, in your LogInViewController...

viewDidAppear 中检查我们是否已经登录,如果是,立即导航到你的startVC:

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];
    }
}

重要的是将它放在viewDidAppear中,而不是(例如)在viewDidLoad中 - 除非初始视图已正确初始化并在屏幕上,否则segue将无法工作。

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.

展开Segue(并在 loginVC @interface )...如果用户退出,loginVC将成为目标VC。

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];

}

更正 - 删除此行:

[[self presentsViewController] dismissViewControllerAnimated:YES
completion:nil];


we不需要解雇,因为segue已经在幕后完成了。这是多余的并记录错误信息

在其他viewControllers中,不管怎样适当的你可以做一个'注销'按钮。 CTRL-从该按钮拖动到故事板中ViewController底部的退出符号,您将能够选择此segue作为展开segue。

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我需要一个连接到3个UICollectionViewControllers的UITabBarController(每个都有一个选项卡)。我必须像根一样把UITabBarController?如果是,我如何处理它们之间的其他Viewontrollers?像这样:

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:

我想你正在试图弄清楚tabBarController如何与之前的viewController(startVC)中的NavigationController相关。答案是,它不应该 - 你真的不想在前面的Nav控制器中嵌入Tab Bar VC,因为它会为Tab Bar的子viewControllers创造奇怪的情况。

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.

从startVC到tabBarVC的导航应该是一个模态segue,而不是push segue。

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

你可以在startVC中另一个展开Segue以便于从你的tabBarController的viewControllers:

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

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

}

更正 - 删除此行:
[[self presentsViewController] dismissViewControllerAnimated:YES completion:nil];
此方法不需要任何内容​​来执行解雇


3我需要在每个CollectionViewController上使用自定义BarButtonItem(就像你在图像2上看到的全部删除),我需要使用UINavigationController对于每一个?

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?

默认情况下,您不会在tabBarVC中获得导航栏。

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

你可以提供两种方式之一

- 将每个子viewController嵌入它自己的导航控制器中;

- 手动拖动一个导航栏到EACH子viewController的场景。

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.

两者都可以,这实际上取决于你是否想要导航到其他ViewControllers。

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

你可以那么在左侧或右侧添加barButtonItem以连接到initialVC的展开segue(按住CTRL-拖动到退出符号)。

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天全站免登陆