Re: beginSheet, doesn't stop NSThread
Re: beginSheet, doesn't stop NSThread
- Subject: Re: beginSheet, doesn't stop NSThread
- From: Alastair Houghton <email@hidden>
- Date: Thu, 19 Jul 2007 17:19:19 +0100
On 19 Jul 2007, at 15:01, Micha Fuhrmann wrote:
Hi everyone,
I'm a bit stuck here, any help appreciated. I've got a NSThread
that runs a file copy process, in the process it needs to display
an Alert sheet asking for some user choices. On that sheet I need
to have 4 buttons and a check box. I cannot use NSRunAlertPanel
because I'm constrained to 3 buttons and no go for a check box. So
I'm loading a NIB with a panel and use "beginSheet", the problem is
the thread doesn't stop for the answer like with a NSRunAlertPanel.
Any suggestions?
Yes. Split your code up into multiple methods. For instance:
- (void)foo
{
/* Some code */
NSBeginAlertSheet (@"Really do something?", nil, nil, nil,
mainWindow, self,
@selector
(mySheetDidEnd:returnCode:contextInfo:),
NULL,
NULL, @"Do you really want to do something?");
}
- (void)mySheetDidEnd:(NSSheet *)sheet returnCode:(int)returnCode
contextInfo:(void *)contextInfo
{
if (returnCode != NSAlertDefaultReturn)
return;
/* Do whatever you were going to */
NSBeginAlertSheet (@"Really do somethingElse?", nil, nil, nil,
mainWindow, self,
@selector
(mySecondSheetDidEnd:returnCode:contextInfo:),
NULL,
NULL, @"Do you really want to do something
else?");
}
- (void)mySecondSheetDidEnd:(NSSheet *)sheet returnCode:(int)
returnCode contextInfo:(void *)contextInfo
{
if (returnCode != NSAlertDefaultReturn)
return;
/* Do something else as well */
}
(I've used NSBeginAlertSheet() here, but the same applies to your own
custom sheets.)
If you need to hold state about your operation, you can either do so
using member variables, or you could create an object and pass its
address as the "contextInfo" parameter.
If it gets very complicated, you might be best off using a separate
controller object to drive all of this, but for simple programs, you
can use your application's main controller object.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden