Iphone dismiss keyboard when done pressed

iPhone Development: Resign or dismiss keyboard when return key pressed in UITextView

UITextview is a common UI(User interface) control used in iPhone app development as it allows user to write down long content. One of the most common problem faced by iPhone app developers is to dismiss the keyboard when user press return key on keyboard. All developers are familiar with resignFirstResponder method to dismiss keyboard.

Iphone dismiss keyboard when done pressed

But in case of UITextView when user press return key on keyboard, instead of dismissing keyboard UITextView enters a new line.So what to do, in this case. You will have two methods to dismiss keyboard

ads

1) Either allow user to dismiss keyboard by displaying him UIToolbar on top of keyboard with Done button while interacting with UITextView. So, when user hit done button you can use resignFirstResponder method to dismiss keyboard. Code for dismissing keyboard is shown below

[textView resignFirstResponder ];

2) If you don't want to go with alternate 1, then you can dismiss keyboard via checking \n character appended into string or textview text when user hit return button on keyboard. For this purpose, we will use - (BOOL)textView:( UITextView *)textView shouldChangeTextInRange:( NSRange )range replacementText:( NSString *)text delegate method of UITextView .

Code for dismissing keyboard when user press return button is shown below

Related posts

  • Computer text symbols Heart text symbols❣ I can bet you've seen the ♥ heart symbol lots of times before on Facebook and Youtube. There also are many other heart symbols you probably...

  • The Best Way to Answer “What’s Your Biggest Weakness?” “You’ve told me about your strengths—now, can you share what you consider to be your biggest weakness?” It’s the question that nobody...

  • Shattered iPhone screen: What would you do? The other day I was at work and all of the sudden I got a text from my wife that her iPhone had "cracked". My wife has been known to tell people that...

  • Ringtonium review: The best ringtone creation app for iPhone Ringtonium is simple and easy to use, and best of all saves you money by letting you use your already purchased songs as ringtones....

  • What exactly is included when I backup my iPhone 4 using iTunes? I have read this question Does an iTunes iOS device backup include everything on the device? but it doesn't seem to be...