iPhone - UITextView的问题 [英] iPhone - Problem with UITextView

查看:117
本文介绍了iPhone - UITextView的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一件容易的事,但我无法弄明白 - 如何在textview结束编辑?怎么才能让键盘消失?或者我是否必须在外面点击以使其消失?

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?

推荐答案

首先,一个(说实话)相当简单的问题像这样让我想知道你是否曾尝试阅读文档或在互联网上搜索。

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.

搜索Apple文档UITextView可以为您提供此链接到类文档。同样,这里是的文档UITextViewDelegate。

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

搜索UITextView简单示例为您提供有用的例子

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

搜索UITextView关闭键盘,第一次点击似乎完全回答你的问题。 (虽然他在返回键上取消了键盘,这可能不是你想要的。)(编辑 - 从你的第二个评论来看,这正是你想要的。)

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.)

PS上面的人是正确的,如果有点简洁(可以理解)。您需要实现UITextViewDelegate。在该委托中,如果要在返回键上隐藏键盘,请实现shouldChangeTextInRange,查找@\ n并在第一个响应者处获得它。或者,在您的用户界面中添加完成编辑按钮,并在用户按下时退出第一响应者。

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.

这篇关于iPhone - UITextView的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆