这是我的项目结构
UIViewController holding:
UIPageViewController holding:
UIViewController1 - holds UILabel
UIViewController2 - holds UILabel
UIViewController3 - holds UILabel
如果我想更新 UIViewController1 中的 UILabel.text,
我如何访问那个 UILabel?
或者如果我想在 UIViewController2 中更改 UILable 怎么办?
最佳答案
在设计方面,您不应该从外部访问 View Controller 的任何 UI 元素,这是不安全的(因为该 UI 元素可能并不总是可用,例如在内存不足或 View 属性尚未附加到任何 View 层次结构时)。 更好的方法是设置变量(或模型变量)的值,其值将在加载时由拥有 View Controller 访问(从 View 加载或 View 将出现)以更新 UI 元素的值。除此之外,您还可以拥有变量/模型的 setter 实现,它将更新 UI 元素。
关于ios - 如何更改位于 UIPageViewController 的 ViewController 中的 label.text?快速 ios xcode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30798705/