Re: Using control:didFailToFormatString:errorDescription:
Re: Using control:didFailToFormatString:errorDescription:
- Subject: Re: Using control:didFailToFormatString:errorDescription:
- From: Rohan Lloyd <email@hidden>
- Date: Tue, 9 Sep 2008 12:10:10 +1000
On 9 Sep 2008, at 12:48 AM, Matt Neuburg wrote:
On Mon, 8 Sep 2008 11:23:30 +1000, Rohan Lloyd <cocoa-
email@hidden> said:
I don't like the vague "Format Error" and want to display my own
message, so I've written my own
control:didFailToFormatString:errorDescription: method (In my
NSWindowController subclass), and set the text field delegate to
point
at it.
- (BOOL)control: (NSControl*)control didFailToFormatString:
(NSString*)str errorDescription: (NSString*)errDescription
{
NSError *error = [NSError errorWithDomain: NSCocoaErrorDomain
code: NSFormattingError userInfo: nil]; // Add custom description
later
[control presentError: error modalForWindow: [self window]
delegate: nil
didPresentSelector: nil
contextInfo: nil];
return YES;
}
First thing's first. Documentation says return value should be:
Return Value
YES if the value in the string parameter should be accepted as is;
otherwise,
NO if the value in the parameter should be rejected.
If you don't like the string, you should not be returning YES. m.
You're right I should have read that part of the documentation.
However, I had tried returning NO, and it didn't really help.
If I return NO, not only do I get my error displayed, but the standard
error dialog is also shown. Which suggests that the return value is
overloaded with a "I have handled this error" meaning. This is backed
up by the following page that I read:
://initgraf.blogspot.com/2007/11/customizing-errors-generated-by.html
Where it says, "You need to return YES, or else you'll get both your
custom error and the standard error."
--
Rohan Lloyd
_______________________________________________
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