2011-05-31 88 views
3

我試圖添加使用此代碼WebViewAlertView如何在UIAlertView中放置一個UIWebView?

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

[search release]; 

[super viewDidLoad]; } 

不過,只有AlertView顯示出來,沒有的WebView。另外,我可以在哪裏獲得有關添加CGRectMakes之類的更多細節?

+0

你能看看這篇文章嗎? http://www.iphonedevsdk.com/forum/iphone-sdk-development/1704-uitextfield-inside-uialertview.html#post10643 – 2011-05-31 11:31:52

回答

6

嘗試添加[search addSubview:googleView];的googlview分配後...

+0

它的工作!謝謝! – Matoe 2011-05-31 11:38:01

+2

如果它的工作意味着嘗試接受答案http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Aravindhan 2011-05-31 11:40:30

+0

哈哈,很好的通知..我們都忽略了:) – 2011-05-31 11:41:16

0

您是否嘗試將addSubview:googleView調用字符串與googleView =字符串進行交換?

0

試試這個

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

} 

首先初始化web視圖的內存,然後將其添加警報視圖中。

0

UIAlertView在iOS的8

不贊成爲了得到實現使用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

當我嘗試這個時,我的webview位於警報的頂部,而不是它的一部分。 – 2017-07-28 03:25:29