2013-10-15 48 views
1

我需要從UIWebView中選擇一些文本。我提到這個答案Getting selected elements programatically from uiwebview?但是,當我使用點擊它選擇文本。但是,它會顯示所有的HTML人物造型也Selected Name: 1       Name of instrumentremove elementFromPoint()顯示HTML字符

-(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); 

} 

回答

0

我得到的答案從stringByReplacingOccurrencesOfString:功能。我在下面的代碼中使用。它工作正常。

tagName=[tagName stringByReplacingOccurrencesOfString:@" " withString:@""];