使用NSUndoManager嵌套的重做组

时间:2012-12-04 13:55:59

标签: nested undo-redo nsundomanager

假设我有两个原子对象方法operation1operation2,它们将自己的撤消操作注册到undoManager。如果我批量生成operation3,则调用前两个操作和组撤消使用beginUndoGrouping/endUndoGrouping的回调,撤消时,NSUndoManager不会对重做操作进行分组。如何将NSUndoManager地图撤消组映射到重做组?

示例代码:

- (void)operation3
{
    [undoManager beginUndoGrouping];
    [self operation1]; // [undoManager setActionName:@"op1"];
    [self operation2]; // [undoManager setActionName:@"op2"];
    [undoManager endUndoGrouping];
    [undoManager setActionName:@"op3"];
    // call operation3 -> "Edit - Undo op3" -- OK
    // press Command+Z -> "Edit - Redo op1" -- not OK
}

1 个答案:

答案 0 :(得分:0)

您必须在撤消期间再次设置操作名称。我认为你在撤销过程中只设置了“op1”。