简体   繁体   中英

iOS - UIButton's text is getting set back to nib set value when pressing

I have a UIButton that has an initial value that I have set in interface builder. When pressing this button, I show a modal view controller which, after some user interaction, passes a value back to the first controller. I then update the button's text with this value that was passed back.

All this works fine, however, if I press this button again, as the modal view controller is animating on screen, the button which I pressed has the original text that it had when the view first loaded. Does anyone know why this is and how to make it retain the new text that I set on it?

Thanks in advance.

When you set the title of the button make sure to set it for UIControlStateNormal and UIControlStateHighlighted

[button setTitle:@"YourNewTitle" forState:UIControlStateNormal];
[button setTitle:@"YourNewTitle" forState:UIControlStateHighlighted];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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