I am implementing a format bar which is used for Rich Text Editing. Among them I have two buttons Undo and Redo. I have documentation for both on apple developers but could not come up to make Redo work. Problem is I have a UITextView. Whenever user writes each word is registered as undo operation in [textView undoManager] like this in shouldChangeTextInRange.
When user clicks on Undo Button, it is done successfully via code [[_myTextView undoManager] undo]. But when user clicks on Redo Button, redo is not performed.
I have even printed the name when user clicks on redo like this [[_myTextView undoManager] redoActionName] and it prints "Change", name of Action. but nothing happens on the text of TextView.
I have searched alot but in every case people are using Interface Builder for undo and automatic redo but I am working with code. Also note even on Ipad the build in button on keyboard for redo does not work after i do undo with keyboard button. Kindly guide me.
-(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];
}