Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - Problem with UITextView

This is probably an easy thing to do, but I just can't figure it out - how do I end editing athe textview? how can I get the keyboard to disappear? or do I have to click outside it to make it go away?

like image 491
Hans Espen Avatar asked May 20 '09 19:05

Hans Espen


People also ask

What is UITextView used for?

UITextView supports the display of text using custom style information and also supports text editing. You typically use a text view to display multiple lines of text, such as when displaying the body of a large text document.

How do I display multiple text styles in UITextView?

UITextView supports the display of text using custom style information and also supports text editing. You typically use a text view to display multiple lines of text, such as when displaying the body of a large text document. This class supports multiple text styles through use of the attributedText property.

What are some common problems with the iPhone?

A Guide to Fix 21 common iPhone Problems. 1 iPhone White Screen of Death. 2 Lost iPhone Data after Upgrade or Jailbreak. 3 Water Damaged iPhone. 4 iPhone Battery Life Problems. 5 iPhone Black Screen. 6 Overheating iPhone. 7 iPhone Camera Roll Crash. 8 iTunes Error 3194. 9 Forgot iPhone Passcode or iPhone Disabled. 10 iPhone Stuck on Apple Logo.


1 Answers

First, a (to be honest) fairly simple question like this makes me wonder if you've tried reading the documentation, or searching on the internet.

Searching for "Apple documentation UITextView" gives you this link to the class documentation. Similarly, here is the documentation for the UITextViewDelegate.

Searching for "UITextView simple example" gives you this useful example.

Searching for "UITextView dismiss keyboard", the first hit seems to answer your question exactly. (Although he dismisses the keyboard on a return key, which may not be what you want.) (Edit - it seems from your second comment it's exactly what you want.)

P.S. The people above are correct, if a little terse (understandably). You need to implement a UITextViewDelegate. In that delegate, if you want to hide the keyboard on a return key, implement shouldChangeTextInRange, look for a @"\n" and resign first responder if you get it. Alternatively, add a "Done editing" button to your UI, and resign first responder if the user presses it.

like image 167
Jane Sales Avatar answered Oct 17 '22 05:10

Jane Sales