UIWebView搜索 [英] UIWebView search

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

问题描述

UIWebView 中搜索文本字符串的最佳方法是什么?

What is the best way to search for a string of text in a UIWebView?

推荐答案

我认为最好的办法是:


  1. 创建一个可以找到你的文字的javascript函数

  2. 使用 stringByEvaluatingJavaScriptFromString: (见这里)获取javascript代码的方法

  3. 调用相同的方法来查找 javascript 函数(将此代码放入将采用 aString <的函数中/ code>参数):

  1. Create a javascript function that will find your text
  2. Use the stringByEvaluatingJavaScriptFromString: (see here) method to get the javascript code
  3. Call the same method to look for the javascript function (put this code in a function that will take the aString 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屋!

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