gpt4 book ai didi

ios - 将数据从 MainView 传递到 ContainerView

转载 作者:行者123 更新时间:2023-11-28 09:23:14 25 4
gpt4 key购买 nike

我有这个 Storyboard:

enter image description here和这段代码:

var actualVisibleView : String? = nil

func showSubViewInContainerView(view: String, parms: String?){
let controller = storyboard!.instantiateViewController(withIdentifier: view)

systemContainerView.subviews.forEach { $0.removeFromSuperview() }
systemContainerView.addSubview(controller.view)

if view == "ConceptGalleryView" {

}

addChildViewController(controller)
controller.view.translatesAutoresizingMaskIntoConstraints = false

systemContainerView.addSubview(controller.view)

NSLayoutConstraint.activate([
controller.view.leadingAnchor.constraint(equalTo: systemContainerView.leadingAnchor),
controller.view.trailingAnchor.constraint(equalTo: systemContainerView.trailingAnchor),
controller.view.topAnchor.constraint(equalTo: systemContainerView.topAnchor),
controller.view.bottomAnchor.constraint(equalTo: systemContainerView.bottomAnchor)
])

controller.didMove(toParentViewController: self)

self.actualVisibleView = view
print("OPEN: \(view)")
}

在左侧菜单中,我使用以下代码在此 containerview 中打开各种 View :

showSubViewInContainerView(view: "View1", parms: "1")
showSubViewInContainerView(view: "View2", parms: "2")
showSubViewInContainerView(view: "View3", parms: "3")
showSubViewInContainerView(view: "View4", parms: nil)

例如,我调用了 ConceptGalleryView.swift:

var idGallery = 0

override func viewDidLoad() {
super.viewDidLoad()
}

如何从 showSubViewInContainerView 函数保存 idGallery 参数 - parms?

最佳答案

将其传递到:ViewController 底部。

你必须创建公共(public)变量,这样你就可以从 View Controller 到另一个:

class variables
{
static var name: String = ""
}

并打印出变量:

print("\(variables.name)")

关于ios - 将数据从 MainView 传递到 ContainerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50602909/

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