NSUndoManager 的问题
我读过 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];
}
I read the chapter on undo/redo in the Hillegass book. He only goes over document based applications though. I am using pretty much the same code that is in the book, but I get "appController may not respond to -undoManager" when I use the code below. I know that I have to create an Undo Manager explicitly, but exactly how do I do this. Please give me a step by step explanation. Thanks.
-(void)insertObject:(Accounts *)currentAccount inArrayOfAccountsAtIndex:(int)index
{
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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜想撤消管理器的初始化丢失了。
类的初始化中尝试
在类的开头和
(例如在“viewDidLoad”中)。
I guess there is the initialization of the Undo-Manager missing.
Try
at the beginning of your class and
in the initialization of your class (for example in "viewDidLoad").