Displaying a Progress Sheet

Discussion in 'Mac Programming' started by knightlie, May 14, 2012.

  1. macrumors 6502a

    Joined:
    Feb 18, 2008
    #1
    I have a task object which carries out an operation which takes an undetermined amount of time, so I want to display a "working" message in a sheet along with an indeterminate progress bar. The Task object has a reference to an NSDocument-subclass which has methods for showing and hiding the sheet in the document window.

    When I call the sheet opening method nothing happens because I'm hogging the event loop - how do I call the method in such a way as to have the sheet appear? I assume it's something along the lines of a performSelector: method, but I can't find which one to use.
     
  2. macrumors regular

    Joined:
    Apr 8, 2009
    #2
  3. thread starter macrumors 6502a

    Joined:
    Feb 18, 2008
    #3
    Nothing that complicated. The NSDocument subclass simply calls an execute method of a class which carries out an operation, say cloning selected entities, and this class may or may not need to show the progress sheet. I need to be able to call the NSDocument subclass' showProgressSheet method and have the sheet actually appear. I may also need to update the progress bat on that sheet in the same way.

    In .NET I'd call Application.DoEvents, in Delphi I'd call Application.processMessages.
     
  4. macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #4
    You could detach a new thread, and have that thread perform methods on the main thread to display and manipulate the sheet.
     
  5. macrumors regular

    Joined:
    Apr 8, 2009
    #5
    My bad, saw "task object" and assumed NSTask. There's no equivalent to DoEvents, so you're probably best doing it on a separate thread. The objects NSOperationQueue, NSOperation and its subclasses are likely the easiest way to do this. The Concurrency Programming Guide from Apple will help.

    If you're using Core Data, it isn't thread-safe by default so requires additional considerations.
     
  6. thread starter macrumors 6502a

    Joined:
    Feb 18, 2008
    #6
    Okay, I think NSOperationQueue is what I need, with operations to show the sheet, do the work and hide the sheet. Thanks for your help guys.
     

Share This Page