ios - 如何在 UIAlertView 中添加 UIWebview?

标签 ios uiwebview uialertview addsubview

我尝试使用以下代码:但我得到的只是一个没有 webview 的警报 View 。我应该在哪里更正以获得正确的输出?

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Next Action"message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

        UIWebView *webView = [[UIWebView alloc] init];
        [webView setFrame:CGRectMake(0,0,300,300)];
        [webView loadHTMLString:[@"https://app.acuityscheduling.com/schedule.php?owner=11673736" description] baseURL:nil];
        [alert addSubview:webView];
        [alert show];

最佳答案

您必须添加 UIWebView作为 UIView 的 subview 和 UIView设为accessoryViewUIAlertView .

试试这个方法

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Next Action"message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

UIWebView *webView = [[UIWebView alloc] init];
[webView setFrame:CGRectMake(0,0,300,300)];
[webView loadHTMLString:[@"https://app.acuityscheduling.com/schedule.php?owner=11673736" description] baseURL:nil];

UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 300)];
[view addSubview:webView];
[alert setValue:view forKey:@"accessoryView"];
[alert show];

关于ios - 如何在 UIAlertView 中添加 UIWebview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32779280/

相关文章:

iphone - 如何在 UIToolBar 中添加条形按钮

ios - 使 swift 类符合协议(protocol) - 在静态/类级别

iphone - MKAnnotationView 不可拖动,尽管我认为它已正确实现?

ios - URL 在 UIWebView 和 WKWebView 之间停止加载。仅限 iOS 11

swift - uiactivity 和 uiwebview 委托(delegate)

android - Cocos2d-x 中的警报 View 等效项

ios - 为什么前导/尾随空格显示为 -16?

ios - ViewController 始终加载相同的链接

iphone - UIAlertView 渲染错误

Swift - UIAlertView 中的文本输入