Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton title after hidden = NO

I've a UIButton which I built in Storyboard. Its title is "Hallo" (Entered in Attributes Inspector) It is connected via an Outlet. In viewDidLoad I did the following:

self.myButton.hidden = YES;

In another method I want to change the title and make the button visible:

[self.myButton setTitle:@"Test" forState:UIControlStateNormal];
self.myButton.hidden = NO;

Now the strange thing: For a few milliseconds I see the old title "Hallo" and then it changes to "Test". How could this be? I could understand this behaviour if I make it first visible and then change the text.

like image 642
user2415476 Avatar asked Mar 06 '14 11:03

user2415476


2 Answers

I also had the same issue for the button which I put on uitableview cell. Following code was working for me. It's setting the title for all the status of the button.

[self.myButton setTitle:@"Test" forState:forState:UIControlStateNormal|UIControlStateHighlighted|UIControlStateSelected];
self.myButton.hidden = NO;
like image 128
TharinduKetipe Avatar answered Oct 20 '22 13:10

TharinduKetipe


Check your title for highlighted state of your button too

[self.myButton setTitle:@"Test" forState:UIControlStateNormal];
[self.myButton setTitle:@"Test" forState:UIControlStateHighlighted];
self.myButton.hidden = NO;
like image 1
Fran Martin Avatar answered Oct 20 '22 14:10

Fran Martin