Re: problem with custom NSFormatter and NSTextField
Re: problem with custom NSFormatter and NSTextField
- Subject: Re: problem with custom NSFormatter and NSTextField
- From: Stéphane Sudre <email@hidden>
- Date: Sun, 30 Nov 2003 19:46:58 +0100
-(id)init:(int)forLength
{
self= [super init];
if (self!=nil)
{
pubLength=forLength;
}
return self;
}
- (NSString *)stringForObjectValue:(id)obj
{
return ((obj && [obj isKindOfClass:[NSString class]]) ? obj : @"");
}
- (BOOL)getObjectValue:(id *)obj forString:(NSString *)string
errorDescription:(NSString **)error
{
*obj=[string copy];
return YES;
}
-(BOOL)isPartialStringValid:(NSString *)partialString
newEditingString:(NSString **)newString errorDescription:(NSString
**)error
{
if([partialString length] >pubLength)
{
*newString=nil;
return NO;
}
else
{
return YES;
}
}
On dimanche, novembre 30, 2003, at 07:10 PM, baron.s wrote:
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.
_______________________________________________
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.