In a project, I change a UILabel’s text with setText, a UIButton’s color and after that do a time consuming calculation, followed by an animation.
However, the text’s and color’s change is reflected after the calculation is executed (and before the animation begins) however I want to reflect the changes immediately before calculation (as you guess it is a waiting text)
How can I achieve this?
Move the calculation off the main thread.
All drawing is performed when the run loop gets time. If you are performing a calculation on the main thread, you are blocking the run loop and thus blocking drawing. When the calculation finishes, use performSelectorOnMainThread to start the animation or whatever else needs to happen in the UI when the calculation completes.
Edit:
A quick way to perform your calculation on the main thread but give the run loop a chance to update UI is with a delay call. Use a delay of 0.1 seconds or so. You can do essentially the same thing with an NSTimer. This is in NSRunLoop.h
- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay;