gpt4 book ai didi

ios - 为什么在使用 TabBarController 时分段控件会隐藏?

转载 作者:行者123 更新时间:2023-11-28 19:37:01 25 4
gpt4 key购买 nike

我想在 iOS 上的 UITabBarController 的选项卡内使用分段控件。它似乎在没有它的情况下工作,但是一旦我将它嵌入 TabBarController 中,分段控件就不会显示在导航栏中。

我是不是遗漏了什么,或者只是因为某些 UI 指南而不受支持?我在 Apple Design Guidelines 中没有找到任何内容......

这是工作版本: storyboard of working example

但在此设置中,分段控件不会显示: storyboard of disappearing segmented control

最佳答案

第一个问题是:您想要实现什么 - 您想要提供什么接口(interface)?

将选项卡栏 Controller 嵌入到导航 Controller 中的情况非常少见。标签栏 Controller 旨在用作主应用程序导航。您可以在众多 Apple 应用程序(音乐、电话等)中找到它

这些应用程序有一个带有多个导航 Controller 的标签栏 Controller 。例如,您的第一个选项卡是一个导航 Controller ,以普通 View Controller 作为根。

在此 Controller 中,您可以设置分段控制。

Apple 在其Combined View Controller Interfaces 文档 ( https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/CombiningViewControllers.html#//apple_ref/doc/uid/TP40011313-CH6-SW1 ) 中描述了此行为。

更新

@kaushal 的回答解决了您的问题……是的。但是,如果您尝试为选项卡 View Controller 中包含的每个 View Controller 设置导航栏的样式(也许您只想为一个 View Controller 添加一个按钮作为 rightBarButtonItem),这是行不通的。

如果您想要在选项卡 View Controller 的每个 Controller 上使用分段控件,只需隔离此控件的代码并在每个 Controller 中重用它。

这会达到相同的效果,但您的软件设计会更简洁。

关于ios - 为什么在使用 TabBarController 时分段控件会隐藏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37705689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com