Re: NSTableView, NSNumberFormatter, and other fun.
Re: NSTableView, NSNumberFormatter, and other fun.
- Subject: Re: NSTableView, NSNumberFormatter, and other fun.
- From: Ondra Cada <email@hidden>
- Date: Fri, 25 Jan 2002 16:00:00 +0100
Greg,
>
>>>>> Greg Anderson (GA) wrote at Thu, 24 Jan 2002 21:56:03 -0600:
GA> ....which sounds like the job of an
GA> NSNumberFormatter. I can't seem to find a way to specify this via
GA> Interface Builder.
Drag the formatter from palette, drop it over the desired column. Then you
can use the Inspector for the column to specifiy the details (a new pane
would occur).
GA> ...In a possibly related thread, I have a couple of functions in
GA> my dataSource for the table view that iterate over the data and return
GA> the max and min temperatures. It works fine until I change a value in the
GA> table (via typing into a cell in the Temperature column). Then my
GA> comparison stops working at this line:
GA>
GA> if ([maxTemp compare:testNumber] == NSOrderedAscending) {
GA>
GA> Where maxTemp is an NSNumber* and testNumber is an NSNumber* that I
GA> get from
GA>
GA> testNumber = [theRecord objectForKey:@"Temp"];
I'd guess you don't use the formatter, and thus this method returns an
NSString. Just check it in gdb, or using
NSLog(@"testNumber is a %@", [testNumber class]);
GA> and theRecord is an NSDictionary pulled from an NSMutableArray, the
GA> kind of stuff one expects when working with the data for a table view.
GA> The error I'm getting reported is
GA>
GA> -[NSCFString objCType]: selector not recognized
Actually you don't need to check it, since the answer is, more or less, here ;)
GA> I'm assuming that this is because when I get testNumber, it's an
GA> NSString, and NSString doesn't understand -compare ... maybe ... ?
It does, but there seems to be some problem caused by mixing strings and
numbers. Actually I'm not that at home with the new CoreFoundation things, so
I'm not exactly sure what happens there...
GA> I'm getting around it by comparing the [maxTemp floatValue] to
GA> [testNumber floatValue], but that seems awfully kludgey. So I'm not sure
GA> if I'm missing something obvious in the world of Obj-C, or if I'm missing
GA> the way to make sure that values entered into a cell in a table view are
GA> of the type I want them to be.
...anyway, if you ensure the objects are of the same class, it should work
well. If you ain't sure, you can check it eg. with asserting [x
isKindOfClass:[NSNumber class]] && [y ...ditto, or alike.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
2K Development: email@hidden
http://www.2kdevelopment.cz
private email@hidden
http://www.ocs.cz/oc