NSUndoManager问题

时间:2010-01-26 06:13:27

标签: 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];
}

1 个答案:

答案 0 :(得分:2)

我猜Undo-Manager的初始化缺失。

尝试

NSUndoManager *undoManager;

在课程开头和

undoManger = [NSUndoManager alloc] init];

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