Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView returnKeyType

I'm trying to change the "Return" key on a UITextView (not UITextField) to a "Done" key. I have the following code that doesn't update the button and leaves the button unchanged. The button starts as a "return" key and if they hit "return" once I want it to change to a "done" key.

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    // this is only run when they hit return once
    textView.returnKeyType = UIReturnKeyDone;
    [textView reloadInputViews];
}
like image 384
user2356157 Avatar asked Apr 07 '26 11:04

user2356157


1 Answers

More than a clean solution, this is a bit of a hack. You could try to hide and show the keyboard (i.e. resignFirstResponder, change the return key style and becomeFirstResponder).

But it will produce a weird animation. To avoid this glitch, you should be able to prevent the screen from being refreshed.

BTW, at the end of this method, do you return YES or NO?

like image 72
MonsieurDart Avatar answered Apr 10 '26 01:04

MonsieurDart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!