首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSUndoManager重做prepareWithInvocationTarget

NSUndoManager重做prepareWithInvocationTarget
EN

Stack Overflow用户
提问于 2013-11-21 02:17:58
回答 1查看 586关注 0票数 0

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

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

代码语言:javascript
复制
- (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];

}
EN

回答 1

Stack Overflow用户

发布于 2013-11-21 02:27:50

在undo方法中,如果从undo调用,则应注册一个undo

代码语言:javascript
复制
- (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];

}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20103788

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档