1

我需要从 UIWebView 中选择一些文本。我提到了这个答案Getting selected elements programmatically from uiwebview? 但是当我使用点击它选择文本时。但它也显示所有 HTML 字符Selected Name: 1       Name of instrument

-(void)singleTap:(UIGestureRecognizer *)gestureRecognizer
 {

     NSLog(@"single tap");

 CGPoint touchPoint = [gestureRecognizer locationInView:wbCont];

 //NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).toString()", touchPoint.x, touchPoint.y];

     NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).innerHTML", touchPoint.x, touchPoint.y];

 NSString * tagName = [wbCont stringByEvaluatingJavaScriptFromString:js];

 NSLog(@"Selected Name: %@",tagName);

 }
4

1 回答 1

0

我从stringByReplacingOccurrencesOfString:函数中得到了答案。我使用下面的代码。它工作正常。

tagName=[tagName stringByReplacingOccurrencesOfString:@" " withString:@""];
于 2013-10-15T08:56:14.653 回答