NSUndoManager 的问题

发布于 2024-08-19 00:35:52 字数 667 浏览 7 评论 0原文

我读过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

婴鹅 2024-08-26 00:35:52

我猜想撤消管理器的初始化丢失了。

类的初始化中尝试

NSUndoManager *undoManager;

在类的开头和

undoManger = [NSUndoManager alloc] init];

(例如在“viewDidLoad”中)。

I guess there is the initialization of the Undo-Manager missing.

Try

NSUndoManager *undoManager;

at the beginning of your class and

undoManger = [NSUndoManager alloc] init];

in the initialization of your class (for example in "viewDidLoad").

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文