【发布时间】:2019-10-20 14:09:48
【问题描述】:
我有 3 个 ViewController:ViewController A 和 ViewController B,以及 Controller C,它实际上是一个由两个 UIView 组成的 ContainerView
如上图所示,ViewController C 有一个清晰的背景,使得在 ViewController A 和 B 的 UIView 中都可以看到“Test Label”。
当我从 ViewController A 向上滑动到 ViewController B 时,我希望能够执行一些动画(淡入/淡出、翻译、更改文本等)。假设我想将文本从“测试标签”更改为“一些新文本”,问题是当我进入 ViewController B 时,我得到“在展开可选值时意外发现 nil”错误。
为什么我得到 nil 以及如何正确更改标签文本?
这段代码似乎有道理,但我无法正确理解:
let containerViewController = ContainerViewController()
containerViewController.testLabel.text = "Some new text"
我也试过了:
let containerViewController = storyboard?.instantiateViewController(withIdentifier: "containerViewController") as! containerViewController
containerViewController.testLabel.text = "Some new text"
我必须在 ViewController A 的 override func prepare 中添加一些东西吗?
【问题讨论】:
标签: ios swift uicontainerview