如何取消UIWebView中的文本字段编辑? [英] How do I cancel a text field edit in a UIWebView?

查看:71
本文介绍了如何取消UIWebView中的文本字段编辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个带有嵌入式UIWebView的应用程序。

I'm working on an application with an embedded UIWebView.

用户可以在Web视图的文本字段中输入位置,但是很费力也可以使用核心位置来发现当前位置。

The user has the ability to enter a location in a text field in the web view but an effort is also made to discover the current location using Core Location.

如果核心位置给出了准确的答案,并且用户当前正在编辑我要取消的位置编辑并以编程方式填充位置字段。这是基于这样的假设,即用户大部分时间都想使用其当前位置,并且如果他们正在编辑字段,他们宁愿自动填充该字段,也不必完成输入位置。

If Core Location comes up with an accurate answer and the user is currently editing the location I'd like to cancel the editing and populate the location field programatically. This is based on the assumption that the vast majority of the time the user will want to use their current location and if they are editing the field they would rather that it was auto-populated than have to finish entering their location.

我的问题是,如何取消UIWebView中的编辑?如果这是一个普通的文本输入字段,我将强制其辞去急救人员的职务,键盘将消失,但我不知道如何使用UIWebView进行操作。无法将resignFirstResponder发送到网络视图。

My question is this, how do I cancel editing within a UIWebView? If it was a normal text entry field I would force it to resign first responder and the keyboard would go away but I don't know how to do that with a UIWebView. Sending resignFirstResponder to the web view doesn't do it.

在网络视图上使用Javascript和stringByEvaluatingJavaScriptFromString:是否可以完成某些工作?还有另一种方法吗?

Is there something that can be done using Javascript and stringByEvaluatingJavaScriptFromString: on the web view? Is there another way?

推荐答案

您最好的选择是Javascript方法,研究表单字段焦点值,看看是否可以

Your best bet is the Javascript approach, look into form field focus values and see if you can make it drop focus.

您可能想要的是:

window.blur();

这篇关于如何取消UIWebView中的文本字段编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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