I have working snippet along the lines of:
for (UIButton *b in buttonMapping) {
[b setTitle:@"yo!" forState:UIControlStateNormal];
[NSThread sleepForTimeInterval:1.0];
}
There’s four buttons, all four buttons update. However, instead of updating one per second, four seconds go by & they all update.
How can I force UIButton to update? Or is this not the recommend method for sleeping?
[b setNeedsDisplay];I’d also not recommend sleeping the main thread (like you’re doing here), since that disables all user interaction.
There are a couple of alternatives. One might be to use an
NSTimerto execute a particular method once a second. However, the easier method would be to do something like:Then add a method to UIButton (ie, a category) called
setNormalStateTitle:that simply executes thesetTitle:forControlState:method. With this approach, you won’t need thesetNeedsDisplaymethod at all.