On Aug 10, 2010, at 07:55, Kevin Walzer wrote:
> - (void)printPanelDidEnd:(NSPrintPanel *)printPanel
> returnCode:(int)returnCode contextInfo:(void *)contextInfo {
>
> printResult = [...]
>
> }
>
> @end
>
> And here's the logic in another function of my code:
>
> [printPanel beginSheetWithPrintInfo:printInfo modalForWindow:windowRef
> delegate:printDelegate
> didEndSelector:@selector(printPanelDidEnd:returnCode:contextInfo:)
> contextInfo:printInfo];
>
> if {printResult = NSOkButton} {
> //do print stuff here
> } else {
> return
>
> }
>
> Based on the NSLog statements, I can tell that printResult is being correctly
> updated, but for some reason that value never makes it to the other function.
> I understand the selector method doesn't return a value; that's why I'm
> assigning the value to the printResult variable. I don't believe it should
> be an error of variable scope, as the variable printResult is defined at the
> global level of the code, outside any functions or class definitions.
>
> Any thoughts about what I'm doing wrong here?
Yup. The issue is not whether the didEnd method returns a value. The issue is
the beginSheet pattern is asynchronous. When beginSheet... returns, the didEnd
method has *not* been invoked yet -- the sheet probably isn't even visible yet.
That all happens later, and at the end of all of it, your didEnd method is
invoked so that you can do whatever should happen when the sheet is dismissed.
There isn't any way to make the beginSheet... pattern synchronous. (Well, you
might be able to do it by running the run loop locally, but I wouldn't suggest
considering that approach.) Instead, if you want synchronous behavior, use
runModal instead. That will use a panel (separate window) instead of a sheet,
but that tradeoff is common the to the beginSheet/runModel pattern used
throughout Cocoa.
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]