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

查看:18
本文介绍了iPhone - 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?

推荐答案

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

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

附:上面的人是正确的,如果有点简洁(可以理解).你需要实现一个 UITextViewDelegate.在该委托中,如果您想在返回键上隐藏键盘,请实现 shouldChangeTextInRange,查找 @" " 并在收到第一响应者时辞职.或者,在您的 UI 中添加完成编辑"按钮,并在用户按下它时退出第一响应者.

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 @" " 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天全站免登陆