简体   繁体   English

如何更改位于UIPageViewController的ViewController中的label.text? 迅速的iOS Xcode

[英]How to change label.text located in UIPageViewController's ViewController? swift ios xcode

This is the structure of my project 这是我项目的结构

UIViewController holding:
    UIPageViewController holding:
        UIViewController1 - holds UILabel
        UIViewController2 - holds UILabel
        UIViewController3 - holds UILabel

If I want to update UILabel.text inside UIViewController1 , 如果我想更新UIViewController1中的 UILabel.text

How can I access that UILabel ? 如何访问该UILabel

or what if I want to change UILable inside UIViewController2? 还是要在UIViewController2中更改UILable怎么办?

Design wise you should not access any UI elements of the view controller from outside it's not safe (because that UI element might not always available eg in low memory or when the view property is not yet attached to any view hierarchy). 从设计角度出发,您不应该从不安全的外部访问视图控制器的任何UI元素(因为该UI元素可能并不总是可用的,例如在内存不足或视图属性尚未附加到任何视图层次结构时)。 A better way would be to set the value of a variable (or model variable) whose value will be accessed by the owning view controller when it's loaded (either from view did load or view will appear) to update the value of the UI element. 更好的方法是设置一个变量(或模型变量)的值,该变量的值将在其加载时从拥有的视图控制器访问(从视图加载或出现视图)以更新UI元素的值。 Along with that, you can have a setter implementation of the variable/model which will update the UI element. 除此之外,您还可以使用变量/模型的setter实现来更新UI元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM