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

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

问题描述

我正在尝试实现一个类似于 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
  1. 账户:UITableViewController
  2. UITabBarController
  1. 推文:UITableViewController
    • 推文/用户/等的详细视图

这似乎有效[^1],但根据 -pushViewController:animated: 的 SDK 文档似乎不受支持(强调已添加):

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 的普通子类)非常容易,它很高兴被推送到导航控制器堆栈上,但仍然遵循视图控制器"理念.帐户特定视图(Tweets/Replies/Messages)上的每个标签"都是它自己的视图控制器,就它们而言担心他们会被一个普通的 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天全站免登陆