GUI flush?

Discussion in 'iOS Programming' started by pinsrw, Dec 12, 2010.

  1. pinsrw macrumors regular

    Joined:
    May 30, 2010
    #1
    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.
     
  2. ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #2
    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).
     
  3. pinsrw thread starter macrumors regular

    Joined:
    May 30, 2010
    #3
    Is it possible to update the GUI from the thread? I tried a setText but got a bad access error.
     
  4. ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #4
    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.
     
  5. pinsrw thread starter macrumors regular

    Joined:
    May 30, 2010
  6. firewood, Dec 12, 2010
    Last edited: Dec 12, 2010

    firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #6
    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.
     

Share This Page