UIWebView搜索 [英] UIWebView search
问题描述
在 UIWebView
中搜索文本字符串的最佳方法是什么?
What is the best way to search for a string of text in a UIWebView
?
推荐答案
我认为最好的办法是:
- 创建一个可以找到你的文字的javascript函数
- 使用
stringByEvaluatingJavaScriptFromString:
(见这里)获取javascript代码的方法 -
调用相同的方法来查找
javascript
函数(将此代码放入将采用aString <的函数中/ code>参数):
- Create a javascript function that will find your text
- Use the
stringByEvaluatingJavaScriptFromString:
(see here) method to get the javascript code Call the same method to look for the
javascript
function (put this code in a function that will take theaString
argument):
NSString * findThisStringFnc = [NSString stringWithFormat:@findThisString('%@'),aString];
[self stringByEvaluatingJavaScriptFromString:findThisStringFnc];
NSString *findThisStringFnc = [NSString stringWithFormat:@"findThisString('%@')",aString];
[self stringByEvaluatingJavaScriptFromString:findThisStringFnc ];
将所有这些代码放入一个函数(例如 findAString
)然后从 UIWebView
实例调用它:
[aWebView findAString:@foobar];
Put all this code in a function (findAString
for example) then call it from the UIWebView
instance:
[aWebView findAString:@"foobar"];
这篇关于UIWebView搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!