【发布时间】:2019-09-27 07:53:06
【问题描述】:
有一个视图控制器 B。因此,在 UIView 中的 viewController A 中嵌入了 B 作为子视图控制器。现在,需要在子视图控制器 B 中调用 api 作为子视图添加。因此,只有在将 B 添加为子项时才需要设置检查,然后才需要点击此 api。请在这方面提供帮助。
下面是代码,我如何在 A viewController 中嵌入 B 作为子 View:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vcController: UIViewController = storyboard.instantiateViewController(withIdentifier: "BNameViewController") as! BNameViewController
//add as a childviewcontroller
addChild(vcController)
// Add the child's View as a subview
viewBList.addSubview(vcController.view)
vcController.view.frame = viewBList.bounds
vcController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
// tell the childviewcontroller it's contained in it's parent
vcController.didMove(toParent: self)
viewBList 是视图控制器 A 中的 UIView。 因此,在这种情况下,现在需要在 VC B 中调用 api,而不是当我们从任何其他 VC 导航到 B 时。我尝试通过在 VC B 中声明相同的值和来自 A 的传递值来传递布尔值或字符串,但这是行不通的。请指导。希望我把我的问题说清楚了,如果有任何疑问,请随时提出。
【问题讨论】: