问题描述
目前我正在并在我的网页浏览中显示。网页显示正确。
Currently I am taking this sample website and showing in my webview. The webpage is displaying correctly.
现在我试图找出用户点击uiwebview后选择了哪些数据。
Now I am trying to figure out which data is selected once the user has tapped on the uiwebview.
为此,我可以使用 UITapGestureRecognizer
获得点击CGPoint。
For this I am able to get the CGPoint for the tap by using UITapGestureRecognizer
.
-(void)singleTap:(UIGestureRecognizer *)gestureRecognizer
{
CGPoint touchPoint = [gestureRecognizer locationInView:myWebView];
NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).toString()", touchPoint.x, touchPoint.y];
NSString * tagName = [myWebView stringByEvaluatingJavaScriptFromString:js];
NSLog(@"Selected Name: %@",tagName);
}
// In log it is displaying [object SVGPathElement]
一旦用户选择第一张图中的垂直条
(例如1994/1995/1996),我想得到确切的数据。
I want to get the exact data once user selects the vertical bar in first graph(E.g. 1994/1995/1996).
怎么做?
推荐答案
你没有指明什么是不适合你...无论如何,a几个建议:
You don't specify what is that is not working for you... anyway, a couple of suggestions:
-
在您的点击处理程序中尝试使用以下js:
try with the following js in your tap handler:
NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).innerHTML", touchPoint.x, touchPoint.y];
创建点击手势处理程序时,为其指定一个委托(它可以是您的控制器) ):
when creating your tap gesture handler, specify a delegate for it (it can be your controller):
tap1.delegate = self;
在您的控制器(或Web视图委托)中,定义以下委托方法:
in your controller (or web view delegate), define the following delegate method:
- (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer: (UIGestureRecognizer*)otherGestureRecognizer {
return YES;
}
如果您使用的是iOS 5,请查看。
通过这样做,我能够得到确切的结果所选对象的HTML值。
By doing like this, I am able to get the exact HTML value for the selected object.
这篇关于从uiwebview以编程方式获取所选元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!