私は最終的に2段階のアプローチを取りました。最初のステップは、やり直しスタックをクリアするダミーの元に戻す項目を作成することでした。次に、その元に戻すアイテムを削除するだけで、両方のスタックがクリーンになりました。
self
コードを含むクラスに関連付けられた実際の元に戻すアクションがないため、ダミーの元に戻すターゲットとして使用できました。self
元に戻すスタックに寄与しない任意のオブジェクトに置き換えることができます。
トリックはremoveAllActionsWithTarget
遅延で呼び出すことでした。それ以外の場合は効果がありません。
// End the open undo grouping
[undoManager endUndoGrouping];
// Perform the undo operation, which gets pushed onto the Redo stack
[undoManager undo];
// Add a dummy Undo item to clear the Redo stack
[undoManager registerUndoWithTarget:self selector:nil object:nil];
// Remove the dummy item with a delay, pushing it to the next run loop cycle
[undoManager performSelector:@selector(removeAllActionsWithTarget:)
withObject:self
afterDelay:0.0];