Quote:
Originally Posted by Daryl Musashi
Hi, I have a little problem and I would be gratefull if someone could help me. I got 5 UIButtons placed next to each other and what I wanna do is set image on first button, redraw it so it, wait for 1 second, then set some other image on second button, redraw second button and so on.
I tried to set image on button, then callfunction sleep(1) and so on but it just freezes application for 5 seconds and then redraws all 5 buttons at the same time.
Thanks in advance for any suggestion.
|
UI changes don't take effect until you return from your code and the app visits the event loop.
The sleep function doesn't release control, it locks the app for the specified time.
You should write a routine that updates the image on one button at a time, using an instance variable as a counter.
Lets call the routine updateButton.
Call it from your code, and at the end, have it call itself using the following:
[self performSelector: @selector(updateButton) withObject: nil afterDelay: 1];
That call will queue a call to the specified method. It returns immediately, and then after the specified time goes by, the selector gets called.