• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to run a panel that customizes a new NSDocument
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: How to run a panel that customizes a new NSDocument
      • From: Ben Haller <email@hidden>
References: 
 >How to run a panel that customizes a new NSDocument (From: Ben Haller <email@hidden>)
 >Re: How to run a panel that customizes a new NSDocument (From: Graham Cox <email@hidden>)
 >Re: How to run a panel that customizes a new NSDocument (From: Ben Haller <email@hidden>)
 >Re: How to run a panel that customizes a new NSDocument (From: Quincey Morris <email@hidden>)
 >Re: How to run a panel that customizes a new NSDocument (From: Ben Haller <email@hidden>)

  • Prev by Date: Re: Within UITableViewCell: capturing UISegmentedControl event & Row number?
  • Next by Date: Re: How to run a panel that customizes a new NSDocument
  • Previous by thread: Re: How to run a panel that customizes a new NSDocument
  • Next by thread: Re: How to run a panel that customizes a new NSDocument
  • Index(es):
    • Date
    • Thread