FROM : Joannou Ng
DATE : Sun Apr 10 22:34:59 2005
Hi Chuck,
The reason your progressIndicator isn't animating is because your time
consuming task is freezing the user interface.
Use NSThread's detachNewThreadSelector:toTarget:withObject:
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/
ObjC_classic/Classes/NSThread.html
Then, when your time consuming task is done, call NSObject's
performSelectorOnMainThread:withObject:waitUntilDone:
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/
ObjC_classic/Classes/NSObject.html
Cheers, Joannou.
On 2005 Apr 10, at 15:45, Chuck Soper wrote:
> Hello,
>
> I'm trying to display a custom sheet with Yes/No buttons and a
> indeterminate progress indicator. When the user clicks Yes I need to
> start animating the indicator and start a time consuming task. When
> the task finishes I'd like to display an NSRunAlertPanel then make the
> sheet go away. All of this works great without the progress indicator.
>
> I confirmed that the indicator is connecting properly with this line:
> NSLog(@"maxValue = %d", (int) [doTaskProgress maxValue]);
> Also, I confirmed that the NSProgressIndicator instance in IB is
> indeterminate.
>
> My source is below. Does anyone know how I can get this working? I
> think that the fact that the sheet is modal is preventing the progress
> bar from updating.
>
> Chuck
>
> // from interface
> IBOutlet NSPanel * doTaskSheet;
> IBOutlet NSProgressIndicator *doTaskProgress;
>
> // from implementation
> - (IBAction)doTaskYes:(id)sender;
> {
> doingTask = TRUE;
> [NSApp endSheet:doTaskSheet];
> }
>
> - (IBAction)doTaskNo:(id)sender;
> {
> [NSApp endSheet:doTaskSheet];
> }
>
>
> - (void)askToDoTaskSheetDidEnd:(NSWindow *)sheet
> returnCode: (int)returnCode
> contextInfo: (void *)contextInfo
> {
> if (doingTask) {
>
> [doTaskProgress displayIfNeeded];
> [doTaskProgress startAnimation:nil];
>
> //do time consuming task then display alert then remove sheet
> [self doTimeConsumingTask];
> NSRunAlertPanel(statusString, resultString, @"OK", nil, nil);
>
> [doTaskProgress stopAnimation:nil];
>
> }
>
> doingTask = FALSE;
> [sheet orderOut:self];
> }
>
> //display the sheet and ask user what to do
> - (void)askToDoTaskSheet
> {
> doingTask = FALSE;
>
> [NSApp beginSheet: doTaskSheet
> modalForWindow: mainWindow
> modalDelegate: self
> didEndSelector:
>
> @selector(askToDoTaskSheetDidEnd:returnCode:contextInfo:)
> contextInfo: nil];
>
> }
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (<email_removed>)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/
> <email_removed>
>
> This email sent to <email_removed>
DATE : Sun Apr 10 22:34:59 2005
Hi Chuck,
The reason your progressIndicator isn't animating is because your time
consuming task is freezing the user interface.
Use NSThread's detachNewThreadSelector:toTarget:withObject:
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/
ObjC_classic/Classes/NSThread.html
Then, when your time consuming task is done, call NSObject's
performSelectorOnMainThread:withObject:waitUntilDone:
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/
ObjC_classic/Classes/NSObject.html
Cheers, Joannou.
On 2005 Apr 10, at 15:45, Chuck Soper wrote:
> Hello,
>
> I'm trying to display a custom sheet with Yes/No buttons and a
> indeterminate progress indicator. When the user clicks Yes I need to
> start animating the indicator and start a time consuming task. When
> the task finishes I'd like to display an NSRunAlertPanel then make the
> sheet go away. All of this works great without the progress indicator.
>
> I confirmed that the indicator is connecting properly with this line:
> NSLog(@"maxValue = %d", (int) [doTaskProgress maxValue]);
> Also, I confirmed that the NSProgressIndicator instance in IB is
> indeterminate.
>
> My source is below. Does anyone know how I can get this working? I
> think that the fact that the sheet is modal is preventing the progress
> bar from updating.
>
> Chuck
>
> // from interface
> IBOutlet NSPanel * doTaskSheet;
> IBOutlet NSProgressIndicator *doTaskProgress;
>
> // from implementation
> - (IBAction)doTaskYes:(id)sender;
> {
> doingTask = TRUE;
> [NSApp endSheet:doTaskSheet];
> }
>
> - (IBAction)doTaskNo:(id)sender;
> {
> [NSApp endSheet:doTaskSheet];
> }
>
>
> - (void)askToDoTaskSheetDidEnd:(NSWindow *)sheet
> returnCode: (int)returnCode
> contextInfo: (void *)contextInfo
> {
> if (doingTask) {
>
> [doTaskProgress displayIfNeeded];
> [doTaskProgress startAnimation:nil];
>
> //do time consuming task then display alert then remove sheet
> [self doTimeConsumingTask];
> NSRunAlertPanel(statusString, resultString, @"OK", nil, nil);
>
> [doTaskProgress stopAnimation:nil];
>
> }
>
> doingTask = FALSE;
> [sheet orderOut:self];
> }
>
> //display the sheet and ask user what to do
> - (void)askToDoTaskSheet
> {
> doingTask = FALSE;
>
> [NSApp beginSheet: doTaskSheet
> modalForWindow: mainWindow
> modalDelegate: self
> didEndSelector:
>
> @selector(askToDoTaskSheetDidEnd:returnCode:contextInfo:)
> contextInfo: nil];
>
> }
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (<email_removed>)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/
> <email_removed>
>
> This email sent to <email_removed>
| Related mails | Author | Date |
|---|---|---|
| Chuck Soper | Apr 10, 21:45 | |
| Joannou Ng | Apr 10, 22:34 | |
| Shawn Erickson | Apr 10, 22:48 | |
| Chuck Soper | Apr 10, 23:05 | |
| Hamish Allan | Apr 11, 00:25 | |
| Chuck Soper | Apr 11, 02:09 |






Cocoa mail archive

