• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: 2 interface questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 2 interface questions


  • Subject: Re: 2 interface questions
  • From: Itrat Khan <email@hidden>
  • Date: Thu, 6 Nov 2003 13:58:54 -0500

On Thursday, November 6, 2003, at 01:19 AM, John Kundert-Gibbs wrote:

1, I have a GUI that has 3 text fields in it for files. Currently I have to type the full path and name of file myself. I'd like to pop open a file browser window, and, when I click the "open" (or "save" in one instance) button, have it set the text field with this file. Is there an example anywhere of how to do this in interface builder?

2, My main program loop can take quite a while. Currently I display a percentage done value in my console window, but I'd rather have a blue progress bar go across one of those little windows (with a stop button too). Again, is there an example anywhere of how to build and interface this with my main code?


I don't think the first can be done completely in Interface Builder. You'd typically connect the button to an action in your window controller that opens the shared NSOpenPanel, then set your text field's value to the open panel's resulting filenames.

To update a progress bar, experiment with wrapping your operation in a modal session as follows:

NSModalSession session = [NSApp beginModalSessionForWindow:[self window]];

while (!done)
{
/* Perform incremental work and calculate percent complete. */
percentComplete = [self processNextChunkOfInput];

/* Update the interface. */
[self->progressBar setDoubleValue:percentComplete];
[NSApp runModalSession:session];
}

[NSApp endModalSession:session];


You'll have to figure out how to break up your input into reasonably sized chunks for each iteration of the loop. You don't want the chunks to be too small, or it'll slow down your operation; and you don't want them to be too large, or the progress won't be responsive.

This mechanism will also allow for a Cancel button. For example, you might connect the button to a cancel: action that sets a userCancelled instance variable to YES. The click will be received when you invoke runModalSession, so on the next iteration of the loop, you can abort if userCancelled is YES.

Itrat.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • USB
      • From: David Blanton <email@hidden>
References: 
 >2 interface questions (From: John Kundert-Gibbs <email@hidden>)

  • Prev by Date: Re: Editing and displaying different values in table cells
  • Next by Date: Finder Label Menu Item
  • Previous by thread: 2 interface questions
  • Next by thread: USB
  • Index(es):
    • Date
    • Thread