fahu
fahu

Reputation: 1531

UIButton setTitle doesn't change title immediately

I'm having trouble by writing and reading the title of UIButton.

My problem:

// If I execute this line of code everything works fine, the title gets changed in the UI
[self.lastButtonPressed setTitle:stringDate forState:UIControlStateNormal];

// In the next line of code I want to read the title I've set before, but everything I get is the title of the UIButton before I changed the title.
NSString *myText = [self.lastButtonPressed.titleLabel.text];

Is it possible that [UIButton setTitle] gets called asynchronous? If yes, is there a possibility to make this call synchronous?

Upvotes: 2

Views: 1093

Answers (1)

zaph
zaph

Reputation: 112857

You probably want currentTitle not titleLabel.text. Or perhaps titleForState:UIControlStateNormal.

Upvotes: 6

Related Questions