0
我想按下一個UIBarButtonItem並執行一個操作。當它這樣做時,我正在更改BarButtonItem的標題的名稱。這樣,如果我再次擊中它,我想撤消它執行的操作,而不是將所有操作都改回來。這是我的代碼的一個例子。撤銷IBAction?
- (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"];
}
}
嘗試尋找一個紀念品設計模式,我認爲它就是你正在尋找 – Novarg 2012-04-29 14:11:09
你有一個很好的鏈接? – Jason 2012-04-29 14:17:02
@Novarg你願意提供一個例子嗎? – Jason 2012-04-29 18:17:44