Y
Y
yungarium2018-08-30 15:14:59
iOS
yungarium, 2018-08-30 15:14:59

How to change button text from another class in Xamarin.IOS?

There are 2 classes. It is necessary to change the Title of the button located in another class from the main class. The problem is that the button was created by the constructor, that is, it is non static and there is no access to it. How can I deal with this trouble?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem Voronov, 2018-08-30
@newross

The easy way:
In the "main" class, have a reference to another class in which to implement the button's Title setting method.
The right way:
1. Forget and never remember about static controls.
2. Read about MVVM and other patterns.
3. Implement the application using the pattern you like.

D
DJBlend, 2018-08-30
@DJBlend

You can use messages. If the button text should change, then in the source class we send a message, and in the class in which the button text should change, we subscribe to this message. More details on how it works here: https://metanit.com/sharp/xamarin/5.4.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question