导航控制器中的标签栏控制器,或共享导航根视图 [英] Tab bar controller inside a navigation controller, or sharing a navigation root view

查看:121
本文介绍了导航控制器中的标签栏控制器,或共享导航根视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 Tweetie 应用程序中实现一个UI结构,其行为如下:顶级视图控制器似乎是一个导航控制器,其根视图是一个帐户表视图。如果您点击任何帐户,它将转到第二级,其底部有一个标签栏。每个标签项显示不同的列表,并允许您进一步向下钻取(后续级别不显示选项卡栏)。

I'm trying to implement a UI structured like in the Tweetie app, which behaves as so: the top-level view controller seems to be a navigation controller, whose root view is an "Accounts" table view. If you click on any account, it goes to the second level, which has a tab bar across the bottom. Each tab item shows a different list and lets you drill down further (the subsequent levels don't show the tab bar).

因此,这似乎实现层次结构:

So, this seems like the implementation hierarchy is:


  • UINavigationController

  • UINavigationController

  1. UITableViewController

  2. UITabBarController

  1. Accounts: UITableViewController
  2. UITabBarController

  1. 推文 UITableViewController


    • 推文/用户/ etc的详细视图



这似乎工作[^ 1],但似乎不支持根据SDK文档 -pushViewController:animated:(增加了强调):

This seems to work[^1], but appears to be unsupported according to the SDK documentation for -pushViewController:animated: (emphasis added):


viewController :被推入堆栈的视图控制器。 它不能是标签栏控制器的实例。

viewController: The view controller that is pushed onto the stack. It cannot be an instance of tab bar controller.

我想避免私有API等,但我不知道为什么这种用法明确禁止,即使它似乎工作正常。任何人都知道原因?

I would like to avoid private APIs and the like, but I'm not sure why this usage is explicitly prohibited even when it seems to work fine. Anyone know the reason?

我想过将标签栏控制器作为主控制器,每个选项卡包含单独的导航控制器。问题是每个导航控制器需要共享一个根视图控制器(即 Tweetie 中的Accounts表) - 这似乎不起作用:将表控制器推送到第二个导航控制器似乎从第一个删除它。更不要说选择不同帐户时所有的记账可能会很痛苦。

I've thought about putting the tab bar controller as the main controller, with each of the tabs containing separate navigation controllers. The problem with this is that each nav controller needs to share a single root view controller (namely the "Accounts" table in Tweetie) -- this doesn't seem to work: pushing the table controller to a second nav controller seems to remove it from the first. Not to mention all the book-keeping when selecting a different account would probably be a pain.

我应该如何实现这种正确的方式?

How should I implement this the Right Way?

[^ 1]:选项卡栏控制器需要被子类化,以便该级别的选项卡栏控制器的导航项目与选定选项卡的导航项目保持同步,并且单个选项卡的表控制器需要将其各自的详细视图推送到 self.tabBarController.navigationController 而不是 self.navigationController

[^1]: The tab bar controller needs to be subclassed so that the tab bar controller's navigation item at that level stays in sync with the selected tab's navigation item, and the individual tab's table controller's need to push their respective detail views to self.tabBarController.navigationController instead of self.navigationController.

推荐答案

前两个答案是正确的 - 我不在Tweetie中使用 UITabBarController 很容易写一个自定义的 XXTabBarController (简单的子类 UIViewController ),很高兴推送到nav控制器堆栈,但仍然生活在视图控制器的哲学。每个标签在特定于帐户的视图( Tweets / 回复 / code>)是它自己的视图控制器,就他们而言,他们正在屏幕上被一个简单的 UITabBarController 交换。

The two previous answers got it right - I don't use UITabBarController in Tweetie. It's pretty easy to write a custom XXTabBarController (plain subclass of UIViewController) that is happy to get pushed onto a nav controller stack, but still lives by the "view controller" philosophy. Each "tab" on the account-specific view (Tweets/Replies/Messages) is its own view controller, and as far as they are concerned they're getting swapped around on screen by a plain-ol UITabBarController.

这篇关于导航控制器中的标签栏控制器,或共享导航根视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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