Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 目标c中的重做问题_Objective C_Ipad_Redo - Fatal编程技术网

Objective c 目标c中的重做问题

Objective c 目标c中的重做问题,objective-c,ipad,redo,Objective C,Ipad,Redo,我正在实现一个用于富文本编辑的格式栏。其中我有两个按钮撤销和重做。我有这两个苹果开发者的文档,但无法实现重做。 问题是我有一个UITextView。每当用户写入时,每个单词都会在[textView undoManager]中注册为撤消操作,如中的[shouldChangeTextInRange 当用户单击“撤消”按钮时,通过代码[[u myTextView undoManager]Undo]成功完成。但当用户单击“重做”按钮时,不会执行重做 我甚至在用户点击redo时打印了这个名称,就像这样[[

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

当用户单击“撤消”按钮时,通过代码[[u myTextView undoManager]Undo]成功完成。但当用户单击“重做”按钮时,不会执行重做

我甚至在用户点击redo时打印了这个名称,就像这样[[u myTextView undoManager]redoActionName],它会打印“Change”,即操作名称。但在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];

}

不要调用任何寄存器
TextView已经有了
NSUndoManager
,并且已经配置好了

你需要做的是

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

- (IBAction)redoPressed
{
    [[self.myTextView undoManager] redo];
}

我试过了,但没用。[[self.myTextView undoManager]undo]相当于[[u myTextView undoManager]undo],因为我已经通过Interface Builder链接了它。同时,撤消工作正常,重做不工作。就像我写abcd,然后按undo键,它会变成abc,但按redo键时,它仍然是abc。我也尝试过[[self undoManager]undo],在这种情况下,只有undo可以工作。只需删除,textView:shouldChangeTextInRange:和revertTextView:,它就会开始工作。我同时删除了这两个,然后undo和redo都不起作用。这意味着另一个代码正在更改undoManager的行为。默认情况下,它应该工作正常。你是对的。我已经详细检查了一切。所发生的是我在shouldChangeTextInRange中更改了attributedText,并将TextView的文本设置为newattributedtext并返回FALSE。若我不返回False,那个么系统也会在TextView中写入,并且在TextView中会写入类似于aabbcc的双字符。一个是系统本身,一个是我。另外,若我返回TRUE,“撤消-重做”功能正常,系统会在键入每个单词后自动保存所有信息。但“撤消”会删除系统记录的所有字符,如aabbcc变成aabbc,然后变成aabc。