NSUndoManager实例

undoManager = [self.window undoManager]

-(IBAction)wakeToRight:(id)sender

{

  

    [self walkRight];

}

-(IBAction)wakeToLeft:(id)sender

{

    [self walkLeft];

}

- (void) walkLeft

{

    position = position + 10;

    [[undoManager prepareWithInvocationTarget:self] walkRight];

    [self showTheChangesToThePostion];

}

- (void) walkRight

{

    position = position - 10;

    [[undoManager prepareWithInvocationTarget:self] walkLeft];

    [self showTheChangesToThePostion];

    

}

-(void)showTheChangesToThePostion

{

    NSLog(@"position:%d",position);

}

原文地址:https://www.cnblogs.com/PJXWang/p/5329822.html