- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在Apple上看到这个方法的描述
func addChildViewController(_ childController: UIViewController)
This method is only intended to be called by an implementation of a custom container view controller. If you override this method, you must call super in your implementation.
我明白了,很多例子表明人们在没有 containerViewController
的情况下到处都使用 addChildViewController
。
例如:我没有使用containerView。我在下面添加了?这是正确的吗?
// Create child VC
let childVC = UIViewController()
// Set child VC
self.addChildViewController(childVC)
// Add child VC's view to parent
self.view.addSubview(childVC.view)
// Register child VC
childVC.didMove(toParentViewController: self)
// Setup constraints for layout
childVC.view.translatesAutoresizingMaskIntoConstraints = false
childVC.view.topAnchor.constraint(equalTo: heroView.bottomAnchor).isActive = true
childVC.view.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
childVC.view.widthAnchor.constraint(equalTo: self.view.widthAnchor).isActive = true
childVC.view.heightAnchor.constraint(equalToConstant: height).isActive = true
最佳答案
如文档所述,该方法旨在供可以包含另一个 View Controller 的 View Controller 使用。一个例子是导航和标签栏 Controller 。
如果您实现了一个自定义 Controller ,例如,将一个 Controller 放在屏幕的上半部分和下半部分,当您设置 bottomHalfViewController
属性时,您将调用 addChildViewController
方法让您的 Controller 知道它应该处理该 View Controller ,因为它是 subview Controller 。
这意味着它将转发所有 View 生命周期调用,如 viewWillAppear:
关于ios - addChildViewController 方法只能用于将 subview Controller 添加到 containerViewController 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49480878/
我正在尝试添加 pageviewcontroller给我的containerviewcontroller .但我不知道需要使用哪个segue(Show, Show Detail, Present Mo
我为我的大多数应用程序的 VC 添加了一个小型容器 View ,该 View 将用作购物车预览,显示购物车中的商品数量和总金额。可以从应用程序内的多个位置将内容添加到购物车,因此我正在寻找在发生时更新
ContainerViewController 将方法 -delegateMethod 委托(delegate)给 ChildViewController。 但是在下面的代码中,没有调用-delega
我目前正在尝试构建自己的自定义 ContainerViewController。 我非常熟悉 iOS ViewController 包含 API(在 iOS 5 中引入)和新的 iOS7 ViewCo
我正在开发一个应用程序,需要在 View 和 containerView 之间传递数据。我需要从两个 View 发送和接收数据。 让我更好地解释一下: 我可以通过协议(protocol)更改Label
我有一个带有 tabBar 的 containerView,我想在任何 viewController 上点击按钮时再添加一个 tabBarItem除了tabBarViewController和Cont
所以我有一个 containerView Controller,它基本上就像 splitViewController。 我正在尝试在 containerViewController 中添加一个 UIN
override func viewWillAppear(_ animated: Bool) { if (self.parent?.isKind(of: GuideViewController
我在Apple上看到这个方法的描述 func addChildViewController(_ childController: UIViewController) This method is on
我是一名优秀的程序员,十分优秀!