On 14/02/2011, at 11:01 PM, Kenneth Baxter wrote:

> Hi everyone, I am using a framework where I register as a delegate and when 
> my delegate method is called, I should be able to save my data, and then the 
> framework does different things based on whether the data has been saved or 
> not.
> 
> I need to ask the user for the file name to save as, and then save the file. 
> I have tried both the beginSheetModalForWindow:completionHandler: method and 
> the old 10.5 
> beginSheetForDirectory:file:modalForWindow:modalDelegate:didEndSelector:contextInfo:
>  method, but both of them return immediately, and the framework thinks I 
> haven't saved the file.

These methods do return immediately - that's what they do. They present the 
sheet then return to the event loop.

> Is there some way that I can display the save panel in such a way that it 
> actually blocks until the user has chosen the save or cancel button on the 
> save panel, like what NSRunAlertPanel does? That way, I would be able to get 
> the file name and save the file before the method returned to the framework.


You need to factor your code so that you don't require the sheets to "block". 
That isn't how they work. Instead, while the sheet is displayed, the event loop 
is run normally and will run the sheet modally while running everything else 
(like other documents) as normal. The user can switch away from the document 
displaying the sheet and come back to it later if they want.

The point is that when the sheet ends (the user clicks OK or Cancel) the 
completion method (or block) is run, and it is this code that does the actual 
file saving. The purpose of the sheet is not only to choose the file name and 
location but to trigger the save itself. Rearranging your code so that the file 
save is triggered in this way should be straightforward - just call the save 
method from the sheet's completion method.

--Graham

_______________________________________________

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]

Reply via email to