我有一个具有以下布局的 Storyboard。
我将 4 和 5 推到导航 Controller 2 上。 5 在推时隐藏底栏,当 6 可见时,因为它的选项卡栏项目被选中, View Controller 6 上设置的标题在导航栏中不可见
我的问题是,从界面生成器(XCode5)设置它的最佳方法是什么?
我还尝试将导航项添加到 View Controller 6 并在那里设置标题,但这没有效果。
在写这篇文章时,我意识到 View Controller 6 永远不会被推送到导航 Controller 堆栈上,这就是它没有导航项的原因。当意识到在 View Controller 3 上设置导航项会产生我预期的效果时,我正要放弃这个问题。这是在切换到不同的选项卡时切换导航栏标题。
这当然是因为它们是完全不同的导航 Controller 。反正有没有用我的结构来模拟这种行为?如果不能,你能建议一种替代方法吗?
最佳答案
您不应该将标签栏 Controller 推到导航 Controller 上。
pushViewController:animated: 的 UINavigationBar 类引用说:
Parameters
viewController
The view controller that is pushed onto the stack. This object cannot be an instance of tab bar controller and it must not already be on the navigation stack.
我建议您以模态方式呈现该选项卡栏 Controller 而不是推送它,您将解决这两个问题。要添加带有标题的导航栏,请将 View Controller #6 嵌入到导航 Controller 中,然后在您将呈现的此选项卡栏 Controller 中。
所以你的 Storyboard看起来像这样:
UITabBarController
+ (tab) UINavigationController
+ (push) UITableViewController
+ (push) UITableViewController
+ (modal) UITabBarController
+ (tab) UINavigationController
+ (push) UITableViewController (set title)
关于ios - 从界面构建器为子标签栏 Controller 设置导航栏标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18978593/