首页 > 解决方案 > 无法撤消或重做将行添加到 NSOutlineView 的操作

问题描述

我的大多数撤消/重做操作都已停止工作。我写了一个简单的例子。

aNewNoteFor 成功地将 OutlineItem 添加到其兄弟的父级的子级,并将其插入到其兄弟级之后的 OutlineView 行中。

deleteAChild:应该删除该行并将其从其父级的子级中删除。

但撤消或重做均未启用。

- (void)aNewNoteFor:(OutlineItem*) sibling
{
    //Ignore note. it's unimportant
    Note* note = [self.document makeDraft:YES];
    OutlineItem* newChild = [[OutlineItem alloc]initWithNote:note];
    NSInteger index = [sibling.parent.children indexOfObject:sibling] +1;
    [sibling.parent.children insertObject:newChild atIndex:index];
    newChild.parent = sibling.parent;
    [_document updateChangeCount:NSChangeDone];
    [_outlineOutlet reloadData];
    [_undoManager registerUndoWithTarget:self selector:@selector(deleteAChild:) object:newChild];
}

-(void)deleteAChild: (OutlineItem*)child
{
    OutlineItem* parent = child.parent;
    [parent.children removeObject:child];
    [_outlineOutlet reloadData];
    [_undoManager registerUndoWithTarget:self selector:@selector(aNewNoteFor:) object:parent];
}
''''

标签: delete-rownsoutlineviewundo-redo

解决方案


推荐阅读