Sumit Mishra
Sumit Mishra

Reputation: 119

How to change the text value of label from another controller which added UIViewController

We have a viewController with container view that embed TabBarController. We have added a label control on top in viewController with welcome text. Now we want to change the label text value according to TabBarController called dynamically. How to change/update label text from another controller in xamarin ios native app.

Please guide.

Upvotes: 1

Views: 191

Answers (1)

cnotethegr8
cnotethegr8

Reputation: 7510

The UITabBarController has a delegate. From your parent view controller you want to assign the delegate to self. When the tab bar changes, update the label.

class ViewController: UIViewController, UITabBarControllerDelegate {
    let mainTabBarController = UITabBarController()
    let label = UILabel()

    override func viewDidLoad() {
        super.viewDidLoad()

        // setup views

        mainTabBarController.delegate = self
    }

    func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
        if viewController == <#someViewController#> {
            label.text = ""
        }
        // else ...
    }
}

Upvotes: 1

Related Questions