2016-01-29 2 views
0

Je consomme des données html json dans mon application iOS. La réponse HTML a quelques blocs div avec les méthodes onClick. Quand j'appuie sur ces blocs, j'appelle du code javascript dans la vue web, mais j'ai aussi besoin de connaître ces événements dans mon code source. Par exemple lorsque je tape sur l'élément web et onClick est appelé, j'ai besoin d'appeler une méthode dans le code.comment appeler méthode dans le code ios à partir de la réponse html en utilisant uiwebview

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

    } 
+0

aidez-moi n'importe quel corps –

Répondre

0

Vous pouvez utiliser Textview insted de UIWebview. Utilisez une chaîne attribuée pour charger la réponse html sur textview. Espérons que cette aide.

+0

ce n'est pas possible. J'ai besoin d'utiliser UIWebview seulement –

+0

Quelqu'un répond pour chaîne html dans webview vous pouvez vérifier le lien suivant http://stackoverflow.com/questions/7259331/ios-webview-and-string –

+0

Avez-vous de l'aide? –