2014-12-05 140 views
0

我已成功添加UIWebViewUIAlertView,并在警报弹出窗口中显示Html页面。 但现在我想跟踪UIWebView中的元素。那么你能告诉我怎么才能知道哪个UIButton被点击了UIWebView显示在alert弹出窗口?将UIWebView添加到UIAlertView iOS

代码:

NSString *html [email protected]"<!DOCTYPE html><html><body><form action=\"action_page.php\">First name:<br><input type=\"text\" name=\"firstname\"><br>  Last name:<br>  <input type=\"text\" name=\"lastname\"><br><br> <input type=\"submit\">  </form>    <p>Note that the form itself is not visible.</p>  <p>Also note that the default width of a text field is 20 characters.</p>  </body>  </html>"; 

UIWebView *webView = [[UIWebView alloc] init]; 
[webView setFrame:CGRectMake(0,0,200,400)]; 
NSData *data = [html dataUsingEncoding:NSUTF8StringEncoding]; 
[webView loadData:data MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@"www.google.com"]]; 
webView.delegate = self; 

UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"TEST" message:@"subview" delegate:nil cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil]; 
[av setValue:webView forKey:@"accessoryView"]; 
[av show]; 

回答

0

当你添加你需要委托设置为从警报将存在当前视图控制器的网络视图。因此,在web view delegate方法中,您将能够使用javascript query来跟踪点击事件。

可以取在web view方法:

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 
{ 
     //javascrip evalution code 
} 
+0

我已经加入的UIWebView使用语法UIAlertView中: UIAlertView中* AV = [[UIAlertView中的alloc] initWithTitle:@ “TEST” 消息:@ “子视图” delegate:nil cancelButtonTitle:@“NO”otherButtonTitles:@“YES”,nil]; [av setValue:webView forKey:@“accessoryView”]; [av show]; – Sumit 2014-12-05 05:43:35

+0

是的,对于那个UIviewWeb,您可以将委托给当前视图。 – Esha 2014-12-05 05:44:21

+0

将相同的代码添加到您的问题中,以使其更清晰。您可以将委托设置为'webView.delegate = self'并为web视图添加协议。可能是解决你的点击事件。 – Esha 2014-12-05 05:47:13

相关问题