gpt4 book ai didi

ios - 为什么在导航 Controller 中嵌入 View Controller ,然后在选项卡栏 Controller 中将导航栏附加到选项卡栏 Controller ?

转载 作者:行者123 更新时间:2023-11-29 00:29:20 29 4
gpt4 key购买 nike

当我第一次为我目前在 Storyboard 中开发的应用程序创建基础布局时,我分两步完成:

  1. 选择我的 View Controller 并使用 Editor->Embed In->Navigation Controller。
  2. 再次选择我的 View Controller 并使用 Editor->Embed In->Tab Bar Controller。

这是最终的布局:

问题 1:为什么这些步骤会产生如此奇怪的布局?

在这个奇怪的布局中,似乎暗示导航 Controller 作为其父级附加到选项卡栏 Controller ,这是我可以让导航项显示在应用程序中的唯一方法(在由 View Controller 控制的 View 中右)是将它们放在 Tab Bar Controller 场景的导航栏中。

但是,这会产生各种问题,包括无法在我的 View Controller 文件中为自定义 View 创建 IBOutlet,我将其拖到选项卡栏 Controller 场景中的标题 View 插槽中。同时,将任何内容拖到 View Controller 场景中的导航栏中只会使其在运行时不会出现在应用程序中。

问题 2:如何修复此布局,以便我可以通过控制从导航项拖动到我的 View Controller 文件中?或者一切实际上都是正确的,而我只是想强制一些我不应该做的事情? (我的目的是能够在我的 View Controller 代码中设置自定义标题 View 的文本。)

最佳答案

很明显,如果你想嵌入 MyViewControllerNavigationController 那么你需要改变你的第二步,需要嵌入 NavigationController标签栏 Controller

  1. 选择 MyViewController 并使用 Editor->Embed In->Navigation Controller
  2. 选择 NavigationController 嵌入 MyViewController 并使用 Editor->Embed In->Tab Bar Controller

它应该是这样的。

enter image description here

注意:只有在TabBarItem上进行推送操作时,才需要将MyViewController嵌入到navigationController中> 表示使用 MyViewController,否则只需将 MyViewController 嵌入到 TabBarController 中,无需使用 NavigationController 将其嵌入。

关于ios - 为什么在导航 Controller 中嵌入 View Controller ,然后在选项卡栏 Controller 中将导航栏附加到选项卡栏 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42289604/

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