Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pinsrw

macrumors regular
Original poster
May 30, 2010
194
0
Hi all,

I have a callback that's invoked when a button is pressed. The activities that it performs take a while to run, and I'd like the GUI to update during the callback. The normal behavior in iOS is for the GUI to update after the callback has returned.

Is there any sort of GUI flush function that will permit me to update the GUI during my callback, i.e. without resorting to creating a thread?

Thanks.
 
Hi all,

I have a callback that's invoked when a button is pressed. The activities that it performs take a while to run, and I'd like the GUI to update during the callback. The normal behavior in iOS is for the GUI to update after the callback has returned.

Is there any sort of GUI flush function that will permit me to update the GUI during my callback, i.e. without resorting to creating a thread?

Thanks.

Hate to say it, but you can't do this. When you put these kinds of long running tasks on your main thread, you are tying up the thread that allows your GUI to stay responsive. You have to detach a thread (like 6 lines of code).
 
Hate to say it, but you can't do this. When you put these kinds of long running tasks on your main thread, you are tying up the thread that allows your GUI to stay responsive. You have to detach a thread (like 6 lines of code).

Is it possible to update the GUI from the thread? I tried a setText but got a bad access error.
 
Is it possible to update the GUI from the thread? I tried a setText but got a bad access error.

Do something like:

[self performSelectorOnMainThread:mad:selector(myUiUpdateFunction) withObject:nil waitUntilDone:NO];

With the withObject property, you could pass in a string to set the text to or whatever.
 
In general no. You can't really call the graphics system to do anything. What you do instead, in an event driven UI such as Cocoa Touch, is ask it (politely) to call your code when it's ready to update the display, which it probably won't do until your UI handler is finished.

What you should do instead is ask for your "activities" to be done in the background in another thread later (NSQueue or somesuch); Then do a setNeedsDisplay request, and Return/exit/quit your UI handler.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.