problem with custom NSFormatter and NSTextField
problem with custom NSFormatter and NSTextField
- Subject: problem with custom NSFormatter and NSTextField
- From: "baron.s" <email@hidden>
- Date: Sun, 30 Nov 2003 19:10:13 +0100
I have created a custom very simple formatter.
this formatter is done to limit the number of character that the user
can enter in a NSTextField
i attach this formatter as explained in Cocoa Programming for Mac OS X
This formatter work fine , the NSTextField doesn't accept more
character than specified in the init call.
The problem is that the NSTextField doesn't retain his value. If i quit
the NSTextField with tab the control become empty.
What am i doing wrong ??
S.Baron
BIFormatter.h
#import <Foundation/Foundation.h>
@interface BIFormatter : NSFormatter {
int pubLength;
}
@end
////////////////////////
BIFormatter.m
#import "BIFormatter.h"
@implementation BIFormatter10
-(id)init:(int)forLength
{
if(!self)
{
[super init];
}
pubLength=forLength;
return self;
}
-(NSString *)stringForObjectValue:(id)obj
{
return obj;
}
- (BOOL)getObjectValue:(id *)anObject forString:(NSString *)string
errorDescription:(NSString **)error
{
return YES;
}
-(BOOL)isPartialStringValid:(NSString *)partialString
newEditingString:(NSString **)newString errorDescription:(NSString
**)error
{
int theLength;
theLength=[partialString length];
if(theLength>pubLength)
return NO;
else
return YES;
}
/////////
Attaching the formatter in a NSWindowController Class
BIFormatter *BIFtest=[[BIFormatter alloc]init:10];
[[fieldName setFormatter:BIFtest]retain];
[BIFtest release];
_______________________________________________
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.