Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c NSEndomanager处于无效状态_Objective C_Nsundomanager - Fatal编程技术网

Objective c NSEndomanager处于无效状态

Objective c NSEndomanager处于无效状态,objective-c,nsundomanager,Objective C,Nsundomanager,通过阅读Aaron Hillegass的《Mac OS X的Cocoa编程》(第三版)一书,我现在读到了第9章,在一节的末尾,向RaiseMan添加了撤销功能。Hillegass告诉您向类中添加两个方法MyDocument,然后构建应用程序以查看添加的undo/redo是否正常工作 但是,它不起作用(否则我为什么会在这里?)。它说: 2012-11-27 19:55:16.231 RaiseMan[293:a0f] HIToolbox: ignoring exception 'undo: NSU

通过阅读Aaron Hillegass的《Mac OS X的Cocoa编程》(第三版)一书,我现在读到了第9章,在
一节的末尾,向RaiseMan添加了撤销功能。Hillegass告诉您向类中添加两个方法
MyDocument
,然后构建应用程序以查看添加的undo/redo是否正常工作

但是,它不起作用(否则我为什么会在这里?)。它说:

2012-11-27 19:55:16.231 RaiseMan[293:a0f] HIToolbox: ignoring exception 'undo: NSUndoManager 0x100188a30 is in invalid state, undo was called with too many nested undo groups' that raised inside Carbon event dispatch
(
    0   CoreFoundation                      0x00007fff88c26784 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x00007fff858ddf03 objc_exception_throw + 45
    2   CoreFoundation                      0x00007fff88c265a7 +[NSException raise:format:arguments:] + 103
    3   CoreFoundation                      0x00007fff88c26534 +[NSException raise:format:] + 148
    4   Foundation                          0x00007fff86fd0e17 -[NSUndoManager undo] + 239
    5   AppKit                              0x00007fff8976eeda -[NSApplication sendAction:to:from:] + 95
    6   AppKit                              0x00007fff8979346a -[NSMenuItem _corePerformAction] + 365
    7   AppKit                              0x00007fff897931d4 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 121
    8   AppKit                              0x00007fff89a18cf4 -[NSMenu _internalPerformActionForItemAtIndex:] + 35
    9   AppKit                              0x00007fff898ca9e9 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 136
    10  AppKit                              0x00007fff8977599c NSSLMMenuEventHandler + 321
    11  HIToolbox                           0x00007fff83d937f7 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1002
    12  HIToolbox                           0x00007fff83d92d46 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 395
    13  HIToolbox                           0x00007fff83db0a81 SendEventToEventTarget + 45
    14  HIToolbox                           0x00007fff83ddfc35 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 387
    15  HIToolbox                           0x00007fff83e0ca0a SendMenuCommandWithContextAndModifiers + 56
    16  HIToolbox                           0x00007fff83e0c9c2 SendMenuItemSelectedEvent + 101
    17  HIToolbox                           0x00007fff83e0c8d2 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 150
    18  HIToolbox                           0x00007fff83dedc27 _ZL14MenuSelectCoreP8MenuData5PointdjPP13OpaqueMenuRefPt + 467
    19  HIToolbox                           0x00007fff83ded37c _HandleMenuSelection2 + 453
    20  AppKit                              0x00007fff89646851 _NSHandleCarbonMenuEvent + 236
    21  AppKit                              0x00007fff8961a362 _DPSNextEvent + 1908
    22  AppKit                              0x00007fff89619801 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 155
    23  AppKit                              0x00007fff895df68f -[NSApplication run] + 395
    24  AppKit                              0x00007fff895d83b0 NSApplicationMain + 364
    25  RaiseMan                            0x000000010000160a main + 33
    26  RaiseMan                            0x0000000100001218 start + 52
    27  ???                                 0x0000000000000001 0x0 + 1
)
在控制台中单击撤消或按cmd+z时

我在网上找到了解决方案,但都是关于“撤销组”或类似的东西。
我知道例外情况是关于
嵌套撤消组的
,但我不使用它们(AFAIK),我甚至不知道它们是什么

我不知道我还应该提供什么信息,因此请在注释中询问代码片段等。

供未来读者参考:

Hillegass告诉您添加两个方法:
-insertObject:InEmployeeSatiIndex:
-removeObjectfromEmployeeSatiIndex:
。在第二种方法中,您必须执行以下操作:

NSUndoManager *undo = [self undoManager];
[[undo prepareWithInvocationTarget:self] insertObject:p inEmployeesAtIndex:index];
但我做到了:

NSUndoManager *undo = [self undoManager];
[[undo prepareWithInvocationTarget:self] insertObject:p atIndex:index]; //atIndex: instead of inEmployeesAtIndex: