我读过Hillegass一书中关于撤销/重做的章节。不过,他只介绍基于文档的应用程序。我使用的代码与书中的代码几乎相同,但是当我使用下面的代码时,我得到"appController可能不会响应-undoManager“。我知道我必须显式地创建一个撤销管理器,但是我到底该怎么做呢?请给我一步一步的解释。谢谢。
-(void)insertObject:(Accounts *)currentAccount索引:(Int)inArrayOfAccountsAtIndex{ NSLog(@"Adding %@ to %@",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];
}发布于 2010-11-12 01:24:57
我猜这里缺少Undo-Manager的初始化。
试一试
NSUndoManager *undoManager;在你的课程开始的时候
undoManger = [NSUndoManager alloc] init];在类的初始化中(例如,在“viewDidLoad”中)。
https://stackoverflow.com/questions/2137771
复制相似问题