问题
What is the best way to search for a string of text in a UIWebView?
回答1:
I think that the best to proceed is to:
- 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
javascriptfunction (put this code in a function that will take theaStringargument):NSString *findThisStringFnc = [NSString stringWithFormat:@"findThisString('%@')",aString];
[self stringByEvaluatingJavaScriptFromString:findThisStringFnc ];Put all this code in a function (
findAStringfor example) then call it from theUIWebViewinstance:
[aWebView findAString:@"foobar"];
来源:https://stackoverflow.com/questions/5195390/uiwebview-search