gpt4 book ai didi

cocoa - NSUndoManager 重做prepareWithInitationTarget

转载 作者:行者123 更新时间:2023-12-03 17:53:01 31 4
gpt4 key购买 nike

如何在使用 prepareWithInitationTarget 时设置与设置撤消操作相同的特定重做操作

使用我的方法,重做不起作用(撤消有效)

- (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];

}

最佳答案

在撤消方法中,如果从撤消调用,您应该注册一个撤消

- (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];

}

关于cocoa - NSUndoManager 重做prepareWithInitationTarget,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20103788/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com