I made a .xib with a button, and referenced it with an outlet to "btnActies"
when i do the following (at any given time) in the back-end C# code
btnActies.TitleLabel.Text = "This is a new label!";
When i build and run the app, the label on the button changes to "This is a new label", but then, if I touch the button, the label reverts to the 'default' text i set in the .xib file.
How do i change the label on a Monotouch UIButton and keep this from happening?
When you want to set some text on a UIButton, you do not do it by altering the text of its TextLabel property. You do it by calling its SetTitle method, passing as the second argument, the button state for which the title will be set at runtime. Chetan Bhalara's answer is correct, here is the C#/MonoTouch equivalent:
btnActies.SetTitle ("title", UIControlState.Normal);
They way you are doing it right now doesn't work, because the label's text is changing internally whenever needed, to the title set in Interface Builder (if you have set it), in this case when you tap the button.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With