标签栏控制器应该如何集成到导航控制器工作流程中?

How should a tab bar controller be integrated into a navigation controller workflow?

我的设计工作流程如下:

根据这个描述,在我看来,该应用程序需要一个导航控制器根视图控制器用于登录和 table 视图,然后单击应用程序需要使用的 table 行用于深入研究数据的标签栏控制器。

我似乎无法使用故事板将 UITabBarController 添加到导航控制器。此外,我发现其他提出类似问题的 SO 帖子,但提供的答案中 none 似乎是最新的,或者使用当前 (iOS7/8) 最佳实践来解决此工作流程。有没有办法完成这个工作流程?如果没有,是否有简明的解释可以用来通知设计者和利益相关者?

在导航控制器中嵌入选项卡控制器并不难,您可以通过将导航控制器设置为 rootViewController 来实现,然后进行从 tableview 单元格到 tabBarController 的 segue,这里是 example 您的工作流程。

你可以这样设计你的 UI

  • 将导航控制器设为初始视图控制器
  • 第二个视图是您的登录屏幕
  • 第三个视图是 table 显示您的数据的视图
  • 最后是带有项目视图控制器的标签栏控制器

希望这对您有所帮助....

虽然可行,但不建议在导航栏中嵌入标签栏。我违反了 Apple 指南,用户习惯于将标签栏作为根控制器。

如果您只想在某些情况下显示标签栏,我建议您在导航控制器顶部以模态方式呈现它。


来自Apple

Before creating a tab bar interface, you need to decide how you intend to use a tab bar interface. Because it imposes an overarching organization on your data,you should use one only in these specific ways:

  • Install it directly as a window’s root view controller.
  • Install it as one of the two view controllers in a split view interface. (iPad only)
  • Present it modally from another view controller.
  • Display it from a popover. (iPad only)

Installing a tab bar interface in your app’s main window is by far the most common way to use it. In such a scenario, the tab bar interface provides the fundamental organizing principle for your app’s data, with each tab leading the user to a distinct part of the app. You can use tab bar controllers by themselves or in conjunction with other view controllers to create even more sophisticated interfaces. For more information, see Combined View Controller Interfaces.

It is also possible to present a tab bar controller modally if a very specific need makes doing so worthwhile. For example, you could present a tab bar controller modally in order to edit some complex data set that had several distinct sets of options. Because a modal view fills all or most of the screen (depending on the device), the presence of the tab bar would simply reflect the choices available for viewing or editing the modally presented data. Avoid using a tab bar in this way if a simpler design approach is available.

我检查了你的要求。

虽然 Apple Inc. 不推荐用于常规用例,

https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/TabBarControllers.html#//apple_ref/doc/uid/TP40011313-CH3-SW2

但可以通过以下步骤轻松实现建议的设计原则。

  1. 在故事板中创建类似的设计,请注意导航控制器位于登录屏幕之前。

  1. 实现以下列表方法以编程方式通过列表视图调用特定选项卡。
 (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"test" forIndexPath:indexPath];
    cell.textLabel.text = [NSString stringWithFormat:@"%ld", (long)[indexPath row]];
    return cell;
}
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITabBarController *tbc = [self.storyboard instantiateViewControllerWithIdentifier:@"MainTabbedViewController"];
    tbc.selectedIndex= (long)[indexPath row];
    [self showViewController:tbc sender:self];
}
  1. 如果列表大小是动态的,您也可以通过编程方式创建标签栏项目。

https://24hrstech.wordpress.com/2012/08/19/create-tabbarcontroller-programmatically/

您不能将 TabBarController 从 table 视图单元格推送为 "Push is depricated now"。您可以在 Storyboard 中按照以下步骤操作:

  1. 获取导航控制器初始视图控制器。
  2. 添加 tableview 作为其根视图控制器。
  3. 然后将 TabBarController 添加到故事板。
  4. 然后右键单击 tableView Cell 并 link 使用 "Show".
  5. 将 tableview cell 选择到 TabBarController

我在我目前正在开发的应用程序中使用了类似的功能。在我的应用程序中,

  1. 我已经登录并在导航控制器中注册,一旦 login/sign up 成功,它将转到另一个具有 table 视图的导航控制器。

  2. 单击 table 中的 'Tourism' 单元格后,我将转到一个选项卡栏控制器,其中的选项卡具有关于 4 个不同位置的不同详细信息。在任何选项卡中,您都可以通过单击导航栏中的后退按钮返回成功登录后出现的主 table 视图。

    如果这是您所需要的,我已经按照上述答案中所示的 'embed in' 选项卡栏控制器进行操作。它对我来说非常有效。我的应用程序处于纵向模式。我听说这会在横向模式下产生问题。我是初学者,我没有在横向模式下尝试过同样的操作。

    在登录视图控制器后,为 table 视图嵌入一个新的导航控制器。我在我的应用程序中使用相同的。

您可以使用 MHCustomTabBarController 它是使用 Apple 自定义容器构建的 ViewController API 并且可以嵌套在您的导航控制器中

这是您需要做的。

这里我使用按钮进行导航,因为我没有创建具有完整描述的视图,但不需要将按钮与 Table 视图控制器或标签栏绑定。

1.) Select View Controller 然后转到 Editor>Embed In>Navigation控制器

2.) 将视图控制器与 Table 视图控制器绑定。

3.) 给segue赋予identifire,这样就可以根据登录成功调用perform segue

4.) 为了使用 tabbar 的正确导航流程,您需要先将 tabbar 控制器与 View Controller 绑定,然后将导航控制器嵌入到 tabbar。 类似的方式你也可以将导航控制器嵌入到标签栏控制器,但它不是正确的流程。

5.) 最后希望你的故事板看起来像。

6.) 结果

希望能帮到您解决问题。

Apple 推荐 UITabBarController 主要用作根视图控制器。

在你的情况下,我建议在普通 UIViewController 的视图上使用 UISegmentedControl 而不是 UITabBarController。通过一些逻辑,您可以在建议的 UIViewController 中显示与按下的 UISegmentedControl 段相对应的不同视图。

此外,如果您使用的是导航控制器,则可以将 UISegmentedControl 作为标题嵌入导航栏中。 (请参阅 Phone 应用程序中的 "Recents" 选项卡。