ios - 1 个屏幕包含 2 个 View Controller 的最佳方法

标签 ios swift uiviewcontroller parent-child uistoryboardsegue

我想学习 iOS 中的父子概念。我在应用程序商店中找到了一些应用程序,我喜欢他们的设计。当用户点击 View 更改下方的按钮并调用其 View Controller 时,它们在同一 View Controller 中有 3 个按钮。就像 TabBar 一样。

我尝试创建 3 个 xib 文件。当用户点击按钮时,他们将从 Nib 中唤醒,我将它们添加到我的 containerView subview 中。有用。但我无法在它们之间发送数据,因为没有准备 segue 方法,所以我无法准备它们。

我尝试在 Storyboard 中创建 3 个 viewController,并将它们与 Storyboard ID 一起使用。有用。但仍然无法在它们之间传输数据。

我不明白解决这个问题的最佳方法是什么?我在网上研究了自定义转场父子概念,但我找不到任何东西。

制作如图所示的容器的最佳方法是什么?

谢谢。

When the user taps a button, bottom containerView changes and shows their viewControllers.

最佳答案

我不确定是否有最好的方法,至少在一般意义上是这样。这实际上取决于您的具体需求和应用程序的其他逻辑。

创建 XIB 文件和在 Storyboard 中创建 ViewController 及其 ID 都可以。这里更多的是关于您的首选方式。我想说,今天您可能会看到更多使用 Storyboard 而不是 XIB 文件。

在数据传输方面。有几种方法,如果不是一些非常繁重的逻辑,那么委托(delegate)可以做得很好而且很容易。

关于ios - 1 个屏幕包含 2 个 View Controller 的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32347708/

相关文章:

ios - 在运行时枚举UISupportedExternalAccessoryProtocols

ios - 如何从子viewController中的UITableView更新父 Controller 中UIScrollView的contentSize

swift - Metal/Metal 2 + swift : How to pass complex Swift structure as shader argument?

ios - 我可以嵌入导航 Controller View 以占用自定义 UIViewController 的部分屏幕吗?

objective-c - isMemberOfClass 不能按预期使用 ocunit

ios - UILabel 添加渐变图层

ios - 使用 TPKeyboardAvoiding 类时 UITextField 弹出太高

ios - 如何在 Swift 中获取屏幕边缘的 X 和 Y

objective-c - 应用程序打开时出现黑屏

ios - 更改父 View Controller 的界面方向