Nimmy
Nimmy

Reputation: 13

How I can add UIWebview inside a UIAlertView?

I tried with the following code: But I am getting simply an alert view without webview. Where should I correct to get the proper output?

 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];

Upvotes: 1

Views: 1956

Answers (1)

Dharmesh Dhorajiya
Dharmesh Dhorajiya

Reputation: 3984

You have to add UIWebView as subview of UIView and UIView set as accessoryView of UIAlertView.

Try this way

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];

Upvotes: 9

Related Questions