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"];
}
}