2013-11-20 2 views
0

는 리두는NSUndoManager 다시 실행 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]; 

} 

답변

1

에서 (작업 취소) 작동하지 않는 방법 실행 취소 메서드가 호출되면 실행 취소를 등록해야합니다.

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

}