尝试编辑时,桌面视图上的Coredata绑定NSNumber列崩溃

时间:2013-07-04 05:20:14

标签: xcode core-data tableview nsvaluetransformer

我创建了(没有编码)coredata实体和一个cocoa窗口,它在可编辑的tableview中显示绑定到绑定到实体的数组控制器的行。表中有一个NSNumber列,没有自定义值转换器在编辑时崩溃,因为tableview的列尝试保存为字符串。

所以我创建了一个自定义值转换器,我链接到该列,但我现在得到不同的错误。这是我的代码:

#import "StringToNumberTransformer.h"  
@implementation StringToNumberTransformer  

+ (Class)transformedValueClass { return [NSNumber class]; }  

+ (BOOL)allowsReverseTransformation { return NO; }  

- (id)transformedValue:(id)value {  

    NSNumberFormatter * f = [[NSNumberFormatter alloc] init];  
    [f setNumberStyle:NSNumberFormatterDecimalStyle];  
    NSNumber * _menuId = [f numberFromString:[value stringValue]];  

    return _menuId;  
}  
@end  

这是我点击列后得到的错误:

[EntityName stringValue]: unrecognized selector sent to instance 0x100137de0
    0   CoreFoundation                      0x00007fff876dbb06 __exceptionPreprocess + 198
    1   libobjc.A.dylib                     0x00007fff836593f0 objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff8777240a -[NSObject(NSObject) doesNotRecognizeSelector:] + 186
    3   CoreFoundation                      0x00007fff876ca02e ___forwarding___ + 414
    4   CoreFoundation                      0x00007fff876c9e18 _CF_forwarding_prep_0 + 232
    5   ClickerData                         0x0000000100001439 -[StringToNumberTransformer transformedValue:] + 153
    6   AppKit                              0x00007fff8a556612 -[NSBinder valueForBinding:atIndex:resolveMarkersToPlaceholders:] + 528
    7   AppKit                              0x00007fff8a6bb947 -[NSEditableBinder editableStateAtIndex:] + 80
    8   AppKit                              0x00007fff8a83bc2b -[NSTableBinder tableView:shouldEditTableColumn:row:] + 168
    9   AppKit                              0x00007fff8a94f2b7 -[_NSBindingAdaptor tableView:shouldEditTableColumn:row:] + 157
    10  AppKit                              0x00007fff8a849cd1 -[NSTableView _userCanEditTableColumn:row:] + 65
    11  AppKit                              0x00007fff8a849dad -[NSTableView _userCanSelectAndEditTableColumn:row:] + 97
    12  AppKit                              0x00007fff8a851ec8 -[NSTableView _shouldEditColumn:row:withEvent:] + 121
    13  AppKit                              0x00007fff8a854861 -[NSTableView mouseDown:] + 5858
    14  AppKit                              0x00007fff8a44250e -[NSWindow sendEvent:] + 6853
    15  AppKit                              0x00007fff8a43e644 -[NSApplication sendEvent:] + 5761
    16  AppKit                              0x00007fff8a35421a -[NSApplication run] + 636
    17  AppKit                              0x00007fff8a2f8bd6 NSApplicationMain + 869
    18  ClickerData                         0x0000000100002bf2 main + 34
    19  libdyld.dylib                       0x00007fff842be7e1 start + 0
    20  ???                                 0x0000000000000003 0x0 + 3
)

我在这里做错了什么?我只想输入一个数字并让它保存回实体。 非常感谢

0 个答案:

没有答案