Controls, stringValue, custom NSFormatter and error pointing to 0
Controls, stringValue, custom NSFormatter and error pointing to 0
- Subject: Controls, stringValue, custom NSFormatter and error pointing to 0
- From: Peter Teeson <email@hidden>
- Date: Wed, 19 Nov 2003 21:04:28 -0500
MacOSX 10.2.6 and December 2002 DevTools with August 2003 update.
I have a very simple Cocoa Document app (used basically as a learning
project).
It has three objects, other than labels, in the window:
(0) An NSTextField that is enabled and editable with a custom on the
fly formatter.
- (void)awakeFromNib {
MyEtherNetMACFormatter *myEtherNetMACFormatter =
[[MyEtherNetMACFormatter alloc] init];
[inputMACaddress setFormatter: myEtherNetMACFormatter];
[myEtherNetMACFormatter release];
}
- (BOOL)getObjectValue:(id *)object forString:(NSString *)string
errorDescription:(NSString**)error {
if (([string length] == 0) || ([string length] == 17)) {
*object = string;
return YES;
} else if ([string length] < 17) {
if (0 != error) { // kludge because when called from stringValue we
find that error is set to 0
*error = NSLocalizedString(@"MAC address is too short.", @"Presented
when MAC address is too short");
}
return NO;
} else { // this will never be reached because the formatter makes
sure it's never too long
*error = NSLocalizedString(@"MAC address is too long.",
@"Presented when MAC address is too long");
return NO;
}
}
- (NSString *)stringForObjectValue:(id)object {
if (![object isKindOfClass:[NSString class]]) {
return nil;
}
return object;
}
(1) An NSTextField that is enabled but NOT editable and is used to
display a result.
(2) An NSButton whose action method takes as input the text in the
first field and will generate a result for display in second field.
The problem: is that this line of code in that action method
tempDelimitedString =[inputMACaddress stringValue];
of the button invokes the formatters' getObjectValue method (as per
the documentation of stringValue) but the value of error is zero which
of course SIG's BAD_ACCESS (or however it's spelt).
Why is that?
All other invocations of getObjectValue that I have traced so far
provide me with a non-zero value for error.
Can I make the button, which is after all a control, use the same
formatter?
(Somehow that doesn't make sense to me but I'm new to Cocoa although
not to Mac - since 1984 <grin>)
What should I be doing to deal with this because everything else works
as I had hoped.
TIA for your help
respect...
Peter
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.