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

Re: Formatter Hides String Value


  • Subject: Re: Formatter Hides String Value
  • From: Daniel Todd Currie <email@hidden>
  • Date: Tue, 27 Jul 2004 11:16:09 -0700

Ok, so I found the problem... It occurs when my formatter is a subclass of NSNumberFormatter, but it works fine when it is a subclass of NSFormatter. Is there a method I need to be overriding or something to make my NSNumberFormatter subclass work? Or am I even allowed to subclass NSNumberFormatter? Is this perhaps a bug?

If someone could try changing one of their custom formatters to a subclass of NSNumberFormatter, we could check for reproducability.

-- DTC


On 2004 Jul 26, at 21:53, Daniel Todd Currie wrote:

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.
_______________________________________________
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.


References: 
 >Formatter Hides String Value (From: Daniel Todd Currie <email@hidden>)

  • Prev by Date: Overlaying views to optimise drawing
  • Next by Date: Extra retain count from loading nib with bindings
  • Previous by thread: Formatter Hides String Value
  • Next by thread: Popups, combo boxes and keyboard access
  • Index(es):
    • Date
    • Thread