我正在尝试按下 UIBarButtonItem 并执行一个操作,它确实如此。当它发生时,我正在更改 BarButtonItem 的标题名称。这样,如果我再次点击它,我想撤消它执行的操作,而不是编写所有内容以将其更改回来。这是我的代码示例。
- (IBAction)MyAction:(id)sender{
if([[MyButton title] isEqualToString:@"Test1"]){
//My Action is performed.
[MyButton setTitle:@"Test2"];
[[undoManager prepareWithInvocationTarget:self] MyAction:?];
[undoManager setActionName:@"UndoLastAction"];
}else if ([[MyButton title] isEqualToString:@"Test2"]){
[MyButton setTitle:@"Test1"];
[[undoManager prepareWithInvocationTarget:self]MyAction:?];
[undoManager setActionName:@"UndoLastAction"];
}
}