Custom Behavior On Return For A UITextView

The default behavior for a UITextField on pressing the return key is to execute the textFieldShouldReturn: method of the UITextFieldDelegate.

What if we wanted to create similar behavior with a a UITextView which does not have an equivalent method and by default just creates a new line?

Nick Dalton has come up with a snippet of code that uses the:

textView:shouldChangeTextInRange:replacementText:

method of the UITextViewDelegate to do just that.

You can check the article out here: Handling The Return Key In A UITextView

It’s a very handy bit of code to have as there are many situations where you may want to implement custom behavior when the return key is pressed in a UITextView.

Thanks Nick.

Please post any comments below, thanks.

Would you like to learn iPhone and iPad programming online from professional instructors who have worked for companies such as EA and Disney Mobile?
Click here for to find out about an interactive online iOS development course that is currently being offered at a discount.

Share and Enjoy:
  • RSS
  • Twitter
  • Facebook
  • DZone
  • HackerNews
  • del.icio.us
  • FriendFeed

Related Posts

blog comments powered by Disqus