清除NSUndoManager的Redo堆栈

| 在我的应用程序中,有一些我想以编程方式撤消的操作,而没有给用户单击“重做”的选项。有什么办法清除
NSUndoManager
的重做堆栈?如果不是,并且我将子类化为ѭ0is,是否有任何方法可以访问重做堆栈以清除它?从文档中看不到任何方法。 或者,是否有一种方法可以在不填充重做堆栈的情况下还原当前嵌套撤消组中的更改?我已经在建立一个嵌套的撤消组。     
已邀请:
我最终采取了两步走法。第一步是创建一个虚拟的撤消项,以清除重做堆栈。然后,我只需要删除该撤消项,两个堆栈就都干净了。 我能够使用ѭ2作为虚拟撤消目标,因为我没有与包含代码的类相关的任何实际撤消动作。
self
可以替换为对撤消堆栈无贡献的任何对象。 技巧是延迟调用calling4ѭ,否则不会起作用。
// End the open undo grouping
[undoManager endUndoGrouping];

// Perform the undo operation, which gets pushed onto the Redo stack
[undoManager undo];

// Add a dummy Undo item to clear the Redo stack
[undoManager registerUndoWithTarget:self selector:nil object:nil];

// Remove the dummy item with a delay, pushing it to the next run loop cycle
[undoManager performSelector:@selector(removeAllActionsWithTarget:)
                  withObject:self
                  afterDelay:0.0];
    
[undoManager disableUndoRegistration];
[undoManager undo];
[undoManager enableUndoRegistration];
    

要回复问题请先登录注册