我最近安装了Mountain Lion,并注意到我的Mac应用程序现在具有数据绑定功能,并将int32 NSTableViewCell显示为x,xxx。
即:.storedata文件显示<attribute name="itemid" type="int32">2533</attribute>,而项目在单元格中显示为2,533。我不明白为什么它在Mountain Lion中可以做到这一点,但在Lion中却没有。
如何使单元格显示为2533而不是2,533

发布于 2013-07-02 06:28:45
我最终添加了一个Value Transformer
@implementation ItemIdValueTransformer
+(Class)transformedValueClass
{
return [NSString class];
}
+ (BOOL)allowsReverseTransformation
{
return NO;
}
- (id)transformedValue:(id)value
{
// Remove the ,'s from Mountain Lion and up
NSString *string = [NSString stringWithFormat:@"%li",(long)[value integerValue]];
return string;
}
@end发布于 2013-06-19 02:04:03
这在10.8发行说明中有一定的说明:
NSString本地化格式
在10.8中,在与10.8SDK、-localizedStringWithFormat:和-initWithFormat:locale:(以及朋友)链接的应用程序中,当提供非空区域设置时,现在将执行数字的本地化格式化。以前,这些调用已经进行了小数点处理;因此,在某些语言环境中,逗号将用作小数点分隔符。这一新行为建立在此基础上,使用本地化数字以及数千个分隔符和符号符号的适当位置。
然而,我仍然认为它是一个bug (并将其归档),它有很多问题(处理遗留的UI,手动编辑时偶尔会有错误的行为等)。
对于新的UI,最好在nib中添加一个数字格式化程序,用于显示数字的所有文本字段。
如果(就像我的例子一样)你有许多包含更多文本字段的nib文件,这个丑陋的技巧可能会有帮助:
#import "HHUTextFieldCell.h"
@implementation HHUTextFieldCell //:: NSTextFieldCell
//*****************************************************************************
// Class methods
//*****************************************************************************
+ (void)load {
//
// 10.8 started using thousands separators for text fields. For our legacy
// apps we don't want those. Rather than changing dozens of xib files with
// hundreds of text fields, we use a replacement class to modify the text
// fields to not have a thousands separator.
//
[NSKeyedUnarchiver setClass:[HHUTextFieldCell class] forClassName:@"NSTextFieldCell"];
}
//*****************************************************************************
// Overwritten methods
//*****************************************************************************
- (void)setObjectValue:(id < NSCopying >)object {
//
// If `object` is an NSNumber object and no formatter is set, we instead
// set the description of that number via -setStringValue:. Otherwise
// use the original implementation.
//
if(!self.formatter && [(NSObject *)object isKindOfClass:[NSNumber class]])
{
[super setStringValue:[(NSObject *)object description]];
}
else
{
[super setObjectValue:object];
}
}
@endhttps://stackoverflow.com/questions/17174993
复制相似问题