ios - 从界面构建器为子标签栏 Controller 设置导航栏标题

标签 ios objective-c uinavigationcontroller uitabbarcontroller uistoryboard

我有一个具有以下布局的 Storyboard。

  • 标签栏 Controller
  • --> 导航 Controller
  • ----> TableViewController
  • ----> TableViewController
  • ----> TabBarController(在推送时隐藏底栏)
  • ------> TableViewContrller(设置标题)

  • 我将 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/

    相关文章:

    objective-c - 将 subview 添加到背景/堆栈背面?

    ios - 处理 JSON 时动画卡住

    ios - 恢复状态导航 Controller 后后退按钮标题被截断

    ios - 单击按钮时隐藏 TabBar 并显示 NavigationController 工具栏

    ios - 我如何像在 Objective C 宏中声明那样全局声明变量或函数

    iOS表格 View 单元格图片下载

    ios - 在 TableViewController 和 ViewController 之间进行委托(delegate)

    ios - UITableViewCell 不显示

    ios - 如何在选择的 UITableViewCell 行中传递值

    ios - 动画并不总是从 UIViewControllerAnimatedTransitioning 中的 animateTransition 可见