开发者

How to put an UIWebView inside UIAlertView?

I've tried to add a WebView to the AlertView using this code:

- (void)viewDidLoad {
search = [[UIAlertView alloc] initWithTitle:@"title" message:@"iGoogle" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Search", nil];
[search addSubview:googleView];
googleView开发者_JAVA技巧 = [[UIWebView alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[search show];

[search release];

[super viewDidLoad]; }

Still, only the AlertView shows up, without the WebView. And also, where can I get more details on adding stuff like CGRectMakes?


try to add [search addSubview:googleView]; after the googlview is allocated...


Did you try to interchange addSubview:googleView call string with googleView = string?


Here's a link to something I used a while back to add a subview to a UIAlertView. The "trick" is adding a message param that makes the alert view increase in height, then you place a subview on top of that. I've never tried it with a web view.

http://www.iphonedevsdk.com/forum/iphone-sdk-development/1704-uitextfield-inside-uialertview.html

Also make your you init your webview with a url and implement delegate as necessary.


Try this

- (void)viewDidLoad 
{
googleView = [[UIWebView alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];

search = [[UIAlertView alloc] initWithTitle:@"title" message:@"iGoogle" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Search", nil];

[search addSubview:googleView];

[search show];

[search release];

[super viewDidLoad]; 

}

Initialize the memory for the webview first and then add it inside the alert view.


UIAlertView is deprecated in iOS 8.

To get the same thing implemented use UIAlertController.

NSURL *url = [[NSBundle mainBundle] URLForResource:@"page" withExtension:@"html"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];  
[webView loadRequest:request];

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"HTML" message:nil preferredStyle:UIAlertControllerStyleAlert];
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
webView.backgroundColor = [UIColor clearColor];
[alert.view addSubview:webView];

[self presentViewController:alert animated:YES completion:nil];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜