• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
problem with custom NSFormatter and NSTextField
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: problem with custom NSFormatter and NSTextField
      • From: Stéphane Sudre <email@hidden>
  • Prev by Date: Re: rounding a float
  • Next by Date: Re: do periodic NSTask yet allow sleep?
  • Previous by thread: Re: Dynamic UI
  • Next by thread: Re: problem with custom NSFormatter and NSTextField
  • Index(es):
    • Date
    • Thread