0

我正在实现一个用于富文本编辑的格式栏。其中我有两个按钮撤消和重做。我有关于苹果开发人员的文档,但无法让重做工作。问题是我有一个 UITextView。每当用户写入每个单词时,都会在 [textView undoManager] 中注册为撤消操作,就像在shouldChangeTextInRange中一样。

当用户单击撤消按钮时,通过代码 [[_myTextView undoManager] undo] 成功完成。但是当用户单击重做按钮时,不会执行重做。

当用户像这样单击重做时,我什至打印了名称 [[_myTextView undoManager] redoActionName] 并打印了“更改”,即操作名称。但是TextView的文本没有任何反应。

我进行了很多搜索,但在每种情况下,人们都在使用 Interface Builder 进行撤消和自动重做,但我正在使用代码。还要注意,即使在 Ipad 上,在我使用键盘按钮撤消后,键盘上用于重做的内置按钮也不起作用。请指导我。

-(BOOL) textView: (UITextView *)textView shouldChangeTextInRange:(NSRange) range replacementText: (NSString *) text{

    [[textView undoManager] registerUndoWithTarget:self selector:@selector(revertTextView:) object:textView.attributedText];
    [[textView undoManager] setActionName:NSLocalizedString(@"Change",@" undo")];

}

-(void) revertTextView: (NSAttributedString *) textViewAttString{

    _myTextView.attributedText = textViewAttributedString;

}

-(IBAction) undoClick{

    [[_myTextView undoManager] undo];

}

-(IBAction) redoClick{

    [[_myTextView undoManager] redo];

}
4

1 回答 1

0

不要调用
TextView 已经拥有的任何寄存器NSUndoManager,并且它已配置

你需要做的是

- (IBAction)undoPressed
{
    [[self.myTextView undoManager] undo];
}

- (IBAction)redoPressed
{
    [[self.myTextView undoManager] redo];
}
于 2014-09-26T07:42:44.313 回答