Re: How to run a panel that customizes a new NSDocument
Re: How to run a panel that customizes a new NSDocument
- Subject: Re: How to run a panel that customizes a new NSDocument
- From: "Adam R. Maxwell" <email@hidden>
- Date: Wed, 21 Oct 2009 19:13:39 -0700
On Oct 21, 2009, at 6:38 PM, Ben Haller wrote:
> On 21-Oct-09, at 7:23 PM, Quincey Morris wrote:
>
>> On Oct 21, 2009, at 15:55, Ben Haller wrote:
>>
>>> Clicking cancel in my "choose a model" window returns a nil string to my NSDocumentController subclass -openUntitledDocumentAndDisplay:error:, and I see that nil and immediately return nil myself, since the user has cancelled. That results in a raise from the Kit:
>>
>> If you're using the code you posted earlier (snipped out above), then you're not returning an error object when you return nil at the end of the method.
>
> Well, two points in response to that. One, the NSError documentation says:
>
> In general, a method should signal an error condition by—for example—returning NO or nil rather than by the simple presence of an error object. The method can then optionally return an NSError object by reference, in order to further describe the error.
>
> So if the NSError is required, that seems questionable.
No. If you return nil and the caller passed in an NSError reference, you need to return a valid NSError or at least set *outError = nil. That should fix the crash you showed.
In addition, your code must check the return value of [self makeUntitledDocumentOfType:error:] like this:
NSError *error;
AKDocument *document = [self makeUntitledDocumentOfType:chosenModelName error:&error];
if (nil == document) {
if (outError) *outError = error;
return nil;
}
Checking if (error) is wrong.
> More importantly, however, if I do make an NSError object and pass it back, then the NSDocument architecture displays an error panel to the user that says "No document could be created"! Since the user has just clicked Cancel, that is obviously wrong. If I select New in Interface Builder, then cancel out of it, I don't get a panel warning me that a new document could not be created.
Search for NSUserCancelledError on this page:
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Documents/Articles/ErrorHandling.html
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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