I have a simple form. There are a number of elements. I want a user to see a transitory change in the display to some elements. I set the changes up (changing alpha on a number of objects), do some work in the database, sleep (1) revert the alpha settings and then proceed. The sleep (1) is very apparent, however the objects do not visibly change.
I am assuming that as the sleep is inside my method, it assumes that the method must be completed prior to updating the display. Is there some way to force the graphical changes to be display?
Thanks heaps
The main thread is running a so called run loop. It basically works something like this:
Your code typically runs in the “react to events” stage. You change UI objects, but when you sleep the “update UI” part cannot be executed sleeping has finished. As long as you sleep on the main thread, no UI updates or animations take place and no touches are processed. This is why you never ever may block the main thread.
So you need you change your scheme to be asynchronous, for example by using
performSelector:withObject:afterDelay:ordispatch_after. Or if you’re just doing simple animations, you might want to, useanimateWithDuration:animations:completion:and friends.If you need to do some things that cannot be done asynchronously, you want to run that in a different thread. Then do the UI updates on the main thread, either with
performSelectorOnMainThread:withObject:waitUntilDone:ordispatch_syncordispatch_async(almost all UI updates need to be done on the main thread).