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];
}
4

1 回答 1

2

我猜 Undo-Manager 的初始化丢失了。

尝试

NSUndoManager *undoManager;

在你上课的开始和

undoManger = [NSUndoManager alloc] init];

在类的初始化中(例如在“viewDidLoad”中)。

于 2010-11-11T17:24:56.913 回答