0

Hillegass の本で元に戻す/やり直しの章を読みました。ただし、彼はドキュメントベースのアプリケーションについてのみ説明します。本にあるコードとほぼ同じコードを使用していますが、以下のコードを使用すると「appController may not response to -undoManager」と表示されます。Undo Manager を明示的に作成する必要があることはわかっていますが、正確にはどうすればよいのでしょうか。順を追って説明をお願いします。ありがとう。

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

1 に答える 1

2

Undo-Manager の初期化が欠落していると思います。

試す

NSUndoManager *undoManager;

クラスの始めに

undoManger = [NSUndoManager alloc] init];

クラスの初期化 (「viewDidLoad」など)。

于 2010-11-11T17:24:56.913 に答える