• 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
Formatter Hides String Value
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Formatter Hides String Value


  • Subject: Formatter Hides String Value
  • From: Daniel Todd Currie <email@hidden>
  • Date: Mon, 26 Jul 2004 21:53:32 -0700

I have an NSTextField that is attached to a custom NSNumberFormatter subclass (code below). Whenever this text field is first responder, the formatter works perfectly. However as soon as another object becomes first responder, the contents of my text field disappear.

- The text field works normally when i disconnect it from my formatter subclass in IB.
- I have checked [myTextField stringValue] while the field is not first responder and the string is still intact.
- When the text field becomes first responder again, the string value becomes visible.
- I have attached the formatter subclass to other text fields in other apps, and have had the same problem.

How can the formatter control text visibility in my text field?

Thanks in advance,

-- DTC

======== PTAmplitudeFormatter.h ========

#import <Cocoa/Cocoa.h>

@interface PTAmplitudeFormatter : NSNumberFormatter

@end

======== PTAmplitudeFormatter.m ========

#import "PTAmplitudeFormatter.h"

@implementation PTAmplitudeFormatter

- (BOOL)getObjectValue:(id *)obj forString:(NSString *)string errorDescription:(NSString **)error
{
*obj = string;
return(YES);
}

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

- (BOOL)isPartialStringValid:(NSString *)partialString newEditingString:(NSString **)newString errorDescription:(NSString **)error
{
NSRange foundRange;

// allow numbers, decimal point
NSCharacterSet *disallowedCharacters = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789."] invertedSet];
foundRange = [partialString rangeOfCharacterFromSet:disallowedCharacters];
if(foundRange.location != NSNotFound)
{
*error = @"Amplitude input contains one or more non-numeric characters.";
NSBeep();
return(NO);
}

// limit input to < 1
if([partialString doubleValue] > 1)
{
*error = @"Amplitude input is greater than 1.";
NSBeep();
return(NO);
}

// disallow more than one period
UInt8 i;
BOOL firstPeriod = NO;
for(i = 0; i < [partialString length]; ++i)
{
if([[partialString substringWithRange:NSMakeRange(i, 1)] isEqualTo:@"."])
{
if(firstPeriod)
{
*error = @"Multiple periods are not allowed.";
NSBeep();
return(NO);
}

firstPeriod = YES;
}
}

*newString = partialString;
return(YES);
}

@end
_______________________________________________
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: Formatter Hides String Value
      • From: Daniel Todd Currie <email@hidden>
  • Prev by Date: PrivateFramework: What is @protocol question.
  • Next by Date: Re: PrivateFramework: What is @protocol question.
  • Previous by thread: Re: PrivateFramework: What is @protocol question.
  • Next by thread: Re: Formatter Hides String Value
  • Index(es):
    • Date
    • Thread