将UIWebView添加到UIAlertView iOS

时间:2014-12-05 05:19:18

标签: ios uiwebview uialertview

我已成功将UIWebView添加到UIAlertView并在警告弹出窗口中显示Html页面。 但现在我想跟踪UIWebView中存在的元素。那么请您告诉我如何才能知道在UIButton弹出窗口中显示的UIWebView中点击了哪个alert

代码:

NSString *html =@"<!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];

1 个答案:

答案 0 :(得分:0)

添加该Web视图时,需要将委托设置为存在警报的当前视图控制器。因此,在web view delegate方法中,您可以使用javascript query跟踪点击事件。

你可以在web view方法中获取它:

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