Search Results

Search found 8 results on 1 pages for 'nsformatter'.

Page 1/1 | 1 

  • Make NSFormatter validate NSTextFieldCell continuously

    - by harms
    In Cocoa, I have an NSOutlineView where the cells are NSTextFieldCell. The cell displays values which are strings that are formatted according to certain rules (such as floats or pairs of floats with a space in between). I have made a custom NSFormatter to validate the text, and this seems to work with no problem. However, the cell (or the outline view, I'm unsure what is causing this) only seems to use the formatter at the moment my editing would end. If I type some alphabetic characters into the text field (which violates the formatting rules), these characters show up -- the only way I notice the formatter doing its job is that I'm now prevented from moving keyboard focus away from this cell. If I return the contents of the cell to a valid form, then I can move focus away. I have set both the cell and the outline view to be "continuous". It would be better if I was unable to enter text into the cell in the first place. Is it possible to make it like that, and if so, how?

    Read the article

  • How to make a custom NSFormatter work correctly on Snow Leopard?

    - by Nathan
    I have a custom NSFormatter attached to several NSTextFields who's only purpose is to uppercase the characters as they are typed into field. The entire code for my formatter is included below. The stringForObjectValue() and getObjectValue() implementations are no-ops and taken pretty much directly out of Apple's documentation. I'm using the isPartialStringValid() method to return an uppercase version of the string. This code works correctly in 10.4 and 10.5. When I run it on 10.6, I get "strange" behaviour where text fields aren't always render the characters that are typed and sometimes are just displaying garbage. I've tried enabling NSZombie detection and running under Instruments but nothing was reported. I see errors like the following in "Console": HIToolbox: ignoring exception '*** -[NSCFString replaceCharactersInRange:withString:]: Range or index out of bounds' that raised inside Carbon event dispatch ( 0 CoreFoundation 0x917ca58a __raiseError + 410 1 libobjc.A.dylib 0x94581f49 objc_exception_throw + 56 2 CoreFoundation 0x917ca2b8 +[NSException raise:format:arguments:] + 136 3 CoreFoundation 0x917ca22a +[NSException raise:format:] + 58 4 Foundation 0x9140f528 mutateError + 218 5 AppKit 0x9563803a -[NSCell textView:shouldChangeTextInRange:replacementString:] + 852 6 AppKit 0x95636cf1 -[NSTextView(NSSharing) shouldChangeTextInRanges:replacementStrings:] + 1276 7 AppKit 0x95635704 -[NSTextView insertText:replacementRange:] + 667 8 AppKit 0x956333bb -[NSTextInputContext handleTSMEvent:] + 2657 9 AppKit 0x95632949 _NSTSMEventHandler + 209 10 HIToolbox 0x93379129 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1567 11 HIToolbox 0x933783f0 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 411 12 HIToolbox 0x9339aa81 SendEventToEventTarget + 52 13 HIToolbox 0x933fc952 SendTSMEvent + 82 14 HIToolbox 0x933fc2cf SendUnicodeTextAEToUnicodeDoc + 700 15 HIToolbox 0x933fbed9 TSMKeyEvent + 998 16 HIToolbox 0x933ecede TSMProcessRawKeyEvent + 2515 17 AppKit 0x95632228 -[NSTextInputContext handleEvent:] + 1453 18 AppKit 0x9562e088 -[NSView interpretKeyEvents:] + 209 19 AppKit 0x95631b45 -[NSTextView keyDown:] + 751 20 AppKit 0x95563194 -[NSWindow sendEvent:] + 5757 21 AppKit 0x9547bceb -[NSApplication sendEvent:] + 6431 22 AppKit 0x9540f6fb -[NSApplication run] + 917 23 AppKit 0x95407735 NSApplicationMain + 574 24 macsetup 0x00001f9f main + 24 25 macsetup 0x00001b75 start + 53 ) Can anybody shed some light on what is happening? Am I just using NSFormatter incorrectly? -(NSString*) stringForObjectValue:(id)object { if( ![object isKindOfClass: [ NSString class ] ] ) { return nil; } return [ NSString stringWithString: object ]; } -(BOOL)getObjectValue: (id*)object forString: string errorDescription:(NSString**)error { if( object ) { *object = [ NSString stringWithString: string ]; return YES; } return NO; } -(BOOL) isPartialStringValid: (NSString*) cStr newEditingString: (NSString**) nStr errorDescription: (NSString**) error { *nStr = [NSString stringWithString: [cStr uppercaseString]]; return NO; }

    Read the article

  • how to get NSTextField in custom NSFormatter class

    - by Amit
    i am new to cocoa and objective-c and creating small application having few NStextFields on the window.I have create custom NSformatter to validate the inputs,at some instance i want to get the NStextField within my custom NSformatter to change its backcolor to red to notify user for wrong input value.I didn't getting how to get the currently selected/focused NStextfield for which i want to change backcolor.

    Read the article

  • How to get NSFormatter subclass to work with NSTableColumn sort key and selector?

    - by Andrew
    My setup: I have a sqlite database from which I populate a NSMutableArray of NSDictionary objects this is the DataSource for my NSTableView. One of the columns holds "time", the time is a float that holds seconds. I would like to display the values in this column as minutes:seconds. For instance my data would be 123.4329387 I want to display 2:03 which I have no problem doing with a subclass of NSFormatter (or NSNumberFormatter) applied to my NSTextField in the column. I have sorting set up by using the Table Column Attributes in IB, I just have the sort key set to "time" and the selector set to "compare:" which works fine without the formatter. Currently this gives me something like this when I sort (descending) 1:37, 1:31, 0:10, 0:10, 0:09, 1:30, 1:30, 1:26, 0:09 and similar nonsense, it looks like something is going on but it's definitely not sorted. How do I get the sort to look at the underlying data instead of the formatted value? Alternately, how do I specify a custom sort method and where do I put the code for said method? I have searched around quite a bit and have not found anything to help me out with this problem, any help with this is most appreciated.

    Read the article

  • NSFormatter problem: not getting called for the empty string

    - by Enchilada
    I have created a custom formatter for my (read-only) table column. It looks like this: - (NSString *)stringForObjectValue:(id)anObject { NSAssert([anObject isKindOfClass:[NSString class]] && anObject != nil, @"invalid object"); if ([anObject isEqualToString:@""]) return @"EMPTY"; else return [anObject stringByAppendingString:@"++"]; } Very simple. The corresponding objects are just strings, so it's an string-to-string formatter. All non-empty string objects are returned with @"++" appended to them. Empty string objects should be turned into the @"EMPTY" string. The @"++" gets appended to non-empty strings just fine. The problem is, @"EMPTY" never gets shown! My formatter is never called by Cocoa when the underlying object is the empty string. The corresponding row just keeps being empty, instead of showing my requested @"EMPTY". Any ideas?

    Read the article

  • [Cocoa] Binding CoreData Managed Object to NSTextFieldCell subclass

    - by ndg
    I have an NSTableView which has its first column set to contain a custom NSTextFieldCell. My custom NSTextFieldCell needs to allow the user to edit a "desc" property within my Managed Object but to also display an "info" string that it contains (which is not editable). To achieve this, I followed this tutorial. In a nutshell, the tutorial suggests editing your Managed Objects generated subclass to create and pass a dictionary of its contents to your NSTableColumn via bindings. This works well for read-only NSCell implementations, but I'm looking to subclass NSTextFieldCell to allow the user to edit the "desc" property of my Managed Object. To do this, I followed one of the articles comments, which suggests subclassing NSFormatter to explicitly state which Managed Object property you would like the NSTextFieldCell to edit. Here's the suggested implementation: @implementation TRTableDescFormatter - (BOOL)getObjectValue:(id *)anObject forString:(NSString *)string errorDescription:(NSString **)error { if (anObject != nil){ *anObject = [NSDictionary dictionaryWithObject:string forKey:@"desc"]; return YES; } return NO; } - (NSString *)stringForObjectValue:(id)anObject { if (![anObject isKindOfClass:[NSDictionary class]]) return nil; return [anObject valueForKey:@"desc"]; } - (NSAttributedString*)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(NSDictionary *)attrs { if (![anObject isKindOfClass:[NSDictionary class]]) return nil; NSAttributedString *anAttributedString = [[NSAttributedString alloc] initWithString: [anObject valueForKey:@"desc"]]; return anAttributedString; } @end I assign the NSFormatter subclass to my cell in my NSTextFieldCell subclass, like so: - (void)awakeFromNib { TRTableDescFormatter *formatter = [[[TRTableDescFormatter alloc] init] autorelease]; [self setFormatter:formatter]; } This seems to work, but is extremely patch. On occasion, clicking to edit a row will cause its value to nullify. On other occasions, the value you enter on one row will populate other rows within the table. I've been doing a lot of reading on this subject and would really like to get to the bottom of this. What's more frustrating is that my NSTextFieldCell is rendering exactly how I would like it to. This editing issue is my last obstacle! If anyone can help, that would be greatly appreciated.

    Read the article

  • Binding CoreData Managed Object to NSTextFieldCell subclass

    - by ndg
    I have an NSTableView which has its first column set to contain a custom NSTextFieldCell. My custom NSTextFieldCell needs to allow the user to edit a "desc" property within my Managed Object but to also display an "info" string that it contains (which is not editable). To achieve this, I followed this tutorial. In a nutshell, the tutorial suggests editing your Managed Objects generated subclass to create and pass a dictionary of its contents to your NSTableColumn via bindings. This works well for read-only NSCell implementations, but I'm looking to subclass NSTextFieldCell to allow the user to edit the "desc" property of my Managed Object. To do this, I followed one of the articles comments, which suggests subclassing NSFormatter to explicitly state which Managed Object property you would like the NSTextFieldCell to edit. Here's the suggested implementation: @implementation TRTableDescFormatter - (BOOL)getObjectValue:(id *)anObject forString:(NSString *)string errorDescription:(NSString **)error { if (anObject != nil){ *anObject = [NSDictionary dictionaryWithObject:string forKey:@"desc"]; return YES; } return NO; } - (NSString *)stringForObjectValue:(id)anObject { if (![anObject isKindOfClass:[NSDictionary class]]) return nil; return [anObject valueForKey:@"desc"]; } - (NSAttributedString*)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(NSDictionary *)attrs { if (![anObject isKindOfClass:[NSDictionary class]]) return nil; NSAttributedString *anAttributedString = [[NSAttributedString alloc] initWithString: [anObject valueForKey:@"desc"]]; return anAttributedString; } @end I assign the NSFormatter subclass to my cell in my NSTextFieldCell subclass, like so: - (void)awakeFromNib { TRTableDescFormatter *formatter = [[[TRTableDescFormatter alloc] init] autorelease]; [self setFormatter:formatter]; } This seems to work, but falls down when editing multiple rows. The behaviour I'm seeing is that editing a row will work as expected until you try to edit another row. Upon editing another row, all previously edited rows will have their "desc" value set to the value of the currently selected row. I've been doing a lot of reading on this subject and would really like to get to the bottom of this. What's more frustrating is that my NSTextFieldCell is rendering exactly how I would like it to. This editing issue is my last obstacle! If anyone can help, that would be greatly appreciated.

    Read the article

  • Struggling with currency in Cocoa.

    - by Meltemi
    I'm trying to do something I'd think would be fairly simple: Let a user input a dollar amount, store that amount in an NSNumber (NSDecimalNumber?), then display that amount formatted as currency again at some later time. My trouble is not so much with the setNumberStyle:NSNumberFormatterCurrencyStyle and displaying floats as currency. The trouble is more with how said numberFormatter works with this UITextField. I can find few examples. This thread from November and this one give me some ideas but leaves me with more questions. I am using the UIKeyboardTypeNumberPad keyboard and understand that I should probably show $0.00 (or whatever local currency format is) in the field upon display then as a user enters numerals to shift the decimal place along: Begin with display $0.00 Tap 2 key: display $0.02 Tap 5 key: display $0.25 Tap 4 key: display $2.54 Tap 3 key: display $25.43 Then [numberFormatter numberFromString:textField.text] should give me a value I can store in my NSNumber variable. Sadly I'm still struggling: Is this really the best/easiest way? If so then maybe someone can help me with the implementation? I feel UITextField may need a delegate responding to every keypress but not sure what, where and how to implement it?! Any sample code? I'd greatly appreciate it! I've searched high and low... Edit1: So I'm looking into NSFormatter's stringForObjectValue: and the closest thing I can find to what benzado recommends: UITextViewTextDidChangeNotification. Having really tough time finding sample code on either of them...so let me know if you know where to look?

    Read the article

1