我阅读了 Hillegass 书中有关撤消/重做的章节。不过,他只讨论了基于文档的应用程序。我使用的代码与书中几乎相同,但是当我使用下面的代码时,我得到“appController 可能无法响应 -undoManager”。我知道我必须明确地创建一个撤消管理器,但我究竟该怎么做。请给我一步一步的解释。谢谢。
-(void)insertObject:(Accounts *)currentAccount inArrayOfAccountsAtIndex:(int)index { NSLog(@"添加 %@ 到 %@", currentAccount, arrayOfAccounts);
NSUndoManager *undo = [self undoManager];
[[undo prepareWithInvocationTarget:self]
removeObjectFromArrayOfAccountsAtIndex: index];
if(![undo isUndoing]){
NSLog(@"After the if(![undo isUndoing]) statement");
[undo setActionName:@"Insert Account"];
}
[arrayOfAccounts insertObject:currentAccount atIndex:index];
}