iPhone - Problem with UITextView(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 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iPhone - UITextView 的问题
基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01