首页 > 解决方案 > 有没有一种特殊的方法可以将 ChildViewController 的成员访问到 ViewController 中,在函数 prepare(for: segue) 中使用其他方法?

问题描述

在制作需要'ContainerView'的基本 iOS 应用程序时遇到逻辑问题。

在 ChildView 中添加了一个标签,并将标签命名为 timerGaugeLabel。

@IBOutlet weak var timerGaugeLabel: UILabel!

(无法将成员访问到 ViewController 类中)

使用函数 prepare(for : segue) 并在函数内部本地创建 segue 实例。

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "ChildViewControllerSegue" {
            let childViewController = segue.destination as! ChildViewController
                    }
    }

(数据成员 timerGaugeLabel 可以在函数内访问,但不能在 ViewController.swift 文件中全局访问)

标签: iosswift

解决方案


推荐阅读