ios - 如何将数据从超类传递到子类?
问题描述
我使用 segue 从 FirstViewController 发送数据,我在 ViewController 中接收它,我想从子类访问位于超类中的变量。这是我现在的代码
class ViewController: UIViewController {
public var count: String = ""
}
class Counter {
func loadData(){
print(count)
}
}
结果为空或nil 谢谢
解决方案
类在继承方面与类没有Counter
关系。ViewController
这不是超类/子类关系。
在类中定义ViewController
类不会给它任何访问ViewController
实例属性的权限
推荐阅读
- java - 用户输入字符串在输入时的词法等级
- mongodb - 正则表达式不适用于 monodb 中的查找
- c++ - 如何在 C++ 中按 Enter/Return 键退出程序循环?
- java - 在 maven 中工作时,如何修复 selenium 中的 sockettimeout 和 webdriver 异常?
- javascript - 更新nodejs中的对象字段数组
- c# - 预期 8 或 0 字节长 (4)
- logstash - 如何将确切单词后的部分字符串移动到logstash中的另一个字段?
- c++ - 如何从 txt 文件中读取矩阵到模板矩阵?
- java - 如何将参数传递到 pom.xml 作为 maven 目标以并行运行测试?
- javascript - 将图像拆分为多个 div