How about take a step back. Is 'nameField' hooked up in IB correctly so that the formatter is actually being set on a real field? You might try logging both 'nameField' and '[nameField formatter]' right after your code to assign it.

Hope this helps,
        Greg

On Feb 17, 2009, at 7:57 AM, Todd Freese wrote:

Still can't this NSFormatter to work. It does not seem to be getting called from my NSTextField.

Here is the formatter:

@implementation FileNameFormatter

- (NSString *)stringForObjectValue:(id)anObject
{
        if ([anObject isKindOfClass:[NSString class]]) {
                NSString *sourceString = [NSString stringWithString:anObject];
                return sourceString;
        } else {
                return nil;     
        }       
}

- (BOOL)getObjectValue:(id *)obj forString:(NSString *)aString errorDescription:(NSString **)error
{
        if (aString != NULL) {
                *obj = [NSString stringWithString:aString];
                return YES;
        } else {
                return NO;
        }
}

- (NSAttributedString *)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(NSDictionary *)attributes
{
        return nil;
}

- (BOOL)isPartialStringValid:(NSString **)partialStringPtr
           proposedSelectedRange:(NSRangePointer)proposedSelRangePtr
                          originalString:(NSString *)origString
           originalSelectedRange:(NSRange)origSelRange
                        errorDescription:(NSString **)error
{
        NSLog(@"formatter called");
        return NO;
}

@end

And here is how I assign it to the NSTextField:

FileNameFormatter *fileNameFormatter = [[[FileNameFormatter alloc] init] autorelease];
[nameField setFormatter:fileNameFormatter];

Any ideas?

Todd Freese




_______________________________________________

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/greg%40omnigroup.com

This email sent to [email protected]

_______________________________________________

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