【发布时间】:2016-01-29 06:27:39
【问题描述】:
我在我的 iOS 应用程序中使用 html json 数据。 HTML 响应几乎没有带有 onClick 方法的 div 块。当我点击这些块时,我会在 Web 视图中调用一些 javascript 代码,但我还需要在我的源代码中了解这些事件。
例如,当我点击 web 元素并调用 onClick 时,我需要在代码中调用一些方法。
- (void)patientResponse:(UIWebView *)webView modeDict:(NSDictionary *)modeDict
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString *protocolPrefix = EVENT;
NSString *urlStr = [[request URL].absoluteString substringFromIndex:protocolPrefix.length];
urlStr = [urlStr stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSError *jsonError;
NSDictionary *callInfo = [NSJSONSerialization
JSONObjectWithData:[urlStr dataUsingEncoding:NSUTF8StringEncoding]
options:kNilOptions error:&jsonError];
if([[callInfo valueForKey:@"acton"] isEqualToString:Set_id])
[self patientResponse:webView modeDict:callInfo];
return NO;
}
- (void)patientResponse:(UIWebView *)webView modeDict:(NSDictionary *)modeDict
{
NSString *mode = [[modeDict valueForKey:@"params"] valueForKey:@"PatientName"];
self.patientName = mode;
NSLog(@"Patient name is:%@",self.patientName);
}
【问题讨论】:
标签: ios objective-c iphone xcode