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

645 views Asked by At

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,

How can I access that UILabel?

or what if I want to change UILable inside UIViewController2?

1

There are 1 answers

0
Tushar On BEST ANSWER

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 e.g in low memory or when the view property is not yet attached to any view hierarchy). 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. Along with that, you can have a setter implementation of the variable/model which will update the UI element.