“ - [__ NSCFDictionary setObject:forKey:]:发送到不可变对象的mutating方法”在调用selectRowIndexes时:byExtendingSelection:

时间:2012-04-03 16:24:25

标签: objective-c macos cocoa nstableview

我正在尝试使用以下代码更改NSTableView的当前选择:

[self.modesTable selectRowIndexes:indexSet byExtendingSelection:NO];

我收到以下错误:

-[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object

我根本不使用任何字典。有谁知道这可能来自哪里?

这是堆栈跟踪:

2012-04-03 18:14:00.598 TurnMode[7130:403] An uncaught exception was raised
2012-04-03 18:14:00.599 TurnMode[7130:403] -[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object
2012-04-03 18:14:00.603 TurnMode[7130:403] (
    0   CoreFoundation                      0x00007fff8ac44fc6 __exceptionPreprocess + 198
    1   libobjc.A.dylib                     0x00007fff8644cd5e objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff8ac44dfa +[NSException raise:format:arguments:] + 106
    3   CoreFoundation                      0x00007fff8ac44d84 +[NSException raise:format:] + 116
    4   CoreFoundation                      0x00007fff8ac01ec0 -[__NSCFDictionary setObject:forKey:] + 96
    5   TurnMode                            0x0000000100009722 -[FRRMode saveObject:named:] + 210
    6   TurnMode                            0x0000000100008f20 -[FRRMode saveToUserDefaults] + 192
    7   TurnMode                            0x000000010000701d -[FRRPreferencesController tableViewSelectionDidChange:] + 125
    8   Foundation                          0x00007fff877b7d32 __-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_1 + 47
    9   CoreFoundation                      0x00007fff8abedaaa _CFXNotificationPost + 2634
    10  Foundation                          0x00007fff877a3fe7 -[NSNotificationCenter postNotificationName:object:userInfo:] + 65
    11  AppKit                              0x00007fff8bcd51d9 -[NSTableView _sendSelectionChangedNotificationForRows:columns:] + 203
    12  AppKit                              0x00007fff8bcabbfe -[NSTableView _enableSelectionPostingAndPost] + 425
    13  AppKit                              0x00007fff8bcd4045 -[NSTableView _doSelectIndexes:byExtendingSelection:indexType:funnelThroughSingleIndexVersion:] + 2915
    14  TurnMode                            0x0000000100006662 -[FRRPreferencesController syncViewWithTempModel] + 914
    15  TurnMode                            0x0000000100006c76 -[FRRPreferencesController showPreferencesView:] + 438
    16  CoreFoundation                      0x00007fff8ac3475d -[NSObject performSelector:withObject:] + 61
    17  AppKit                              0x00007fff8bc6ecb2 -[NSApplication sendAction:to:from:] + 139
    18  AppKit                              0x00007fff8bd5bfe7 -[NSMenuItem _corePerformAction] + 399
    19  AppKit                              0x00007fff8bd5bd1e -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 125
    20  AppKit                              0x00007fff8bff9dd4 -[NSMenu _internalPerformActionForItemAtIndex:] + 38
    21  AppKit                              0x00007fff8be8a3a9 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 138
    22  AppKit                              0x00007fff8bcd5b4b NSSLMMenuEventHandler + 339
    23  HIToolbox                           0x00007fff8d6f4294 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1263
    24  HIToolbox                           0x00007fff8d6f38a0 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 446
    25  HIToolbox                           0x00007fff8d70a677 SendEventToEventTarget + 76
    26  HIToolbox                           0x00007fff8d7506c1 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 398
    27  HIToolbox                           0x00007fff8d837c59 SendMenuCommandWithContextAndModifiers + 56
    28  HIToolbox                           0x00007fff8d87e73d SendMenuItemSelectedEvent + 253
    29  HIToolbox                           0x00007fff8d7497bb _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 101
    30  HIToolbox                           0x00007fff8d877175 _ZL19PopUpMenuSelectCoreP8MenuData5PointdS1_tjPK4RecttjS4_S4_PK10__CFStringPP13OpaqueMenuRefPt + 1660
    31  HIToolbox                           0x00007fff8d877434 _HandlePopUpMenuSelection7 + 621
    32  AppKit                              0x00007fff8be8d075 _NSSLMPopUpCarbonMenu3 + 3860
    33  AppKit                              0x00007fff8c2386b6 _NSPopUpCarbonMenu3 + 39
    34  AppKit                              0x00007fff8be8b1da -[NSCarbonMenuImpl popUpMenu:atLocation:width:forView:withSelectedItem:withFont:withFlags:withOptions:] + 322
    35  AppKit                              0x00007fff8c0eb8da +[NSStatusBarButtonCell popupStatusBarMenu:inRect:ofView:withEvent:] + 673
    36  AppKit                              0x00007fff8c0ebb85 -[NSStatusBarButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 147
    37  AppKit                              0x00007fff8bc6cbde -[NSControl mouseDown:] + 786
    38  AppKit                              0x00007fff8bc376e0 -[NSWindow sendEvent:] + 6306
    39  AppKit                              0x00007fff8c0ec598 -[NSStatusBarWindow sendEvent:] + 66
    40  AppKit                              0x00007fff8bbd016d -[NSApplication sendEvent:] + 5593
    41  AppKit                              0x00007fff8bb661f2 -[NSApplication run] + 555
    42  AppKit                              0x00007fff8bde4b88 NSApplicationMain + 867
    43  TurnMode                            0x0000000100001ab2 main + 34
    44  TurnMode                            0x0000000100001a84 start + 52
)

2 个答案:

答案 0 :(得分:1)

异常肯定是在-[NSDictionary setObject:forKey:]中调用-[FRRMode saveObject:named:]

如果您确实没有在此方法中使用任何词典,则仍应查找setObject:forKey:。如果你过度释放一个对象,它的内存地址可能被NSDictionary占用,这显然不会响应选择器。

答案 1 :(得分:0)

看起来 - [FRRPreferencesController syncViewWithTempModel]是你调用[self.modesTable selectRowIndexes:indexSet byExtendingSelection:NO]的方法。然后,表格视图尽职地改变其选择。

看起来您的FRRPreferencesController对象是表视图在其选择更改时发布的通知的观察者。反过来,调用 - [FRRMode saveToUserDefaults]调用 - [FRRMode saveObject:named:],并试图改变不可变字典。

从名称saveToUserDefaults,我想知道你是否从NSUserDefaults中获取字典类型的值,然后尝试改变它。即使您将可变集合传递到其-setObject:forKey:,NSUserDefaults也不会保留或返回可变集合。当您以后检索它时,您将获得一个不可变的副本。