使用prepareWithInvocationTarget
时,我如何设置与设置撤消操作相同的特定重做操作
使用我的方法,重做不起作用(撤消起作用)
- (void)removeSmth:(Smth *)smth index:(NSInteger)indexOfSmth {
[self.document.undoManager beginUndoGrouping];
...
[self removeSmth:smth];
[[self.document.undoManager prepareWithInvocationTarget:self] undoInsertSmth:smth index:indexOfSmth];
...
[self.document.undoManager endUndoGrouping];
}
- (void)undoInsertSmth:(Smth *)smth index:(NSUInteger)index {
[self insertSmth:smth index:index];
}
在undo方法中,如果从unding调用,则应注册undo
- (void)removeSmth:(Smth *)smth index:(NSInteger)indexOfSmth {
[self.document.undoManager beginUndoGrouping];
...
[self removeSmth:smth];
[[self.document.undoManager prepareWithInvocationTarget:self] undoInsertSmth:smth index:indexOfSmth];
...
[self.document.undoManager endUndoGrouping];
}
- (void)undoInsertSmth:(Smth *)smth index:(NSUInteger)index {
if ([self.document.undoManager isUndoing]) {
[[self.document.undoManager prepareWithInvocationTarget:self] removeSmth:smth index:index];
}
[self insertSmth:smth index:index];
}