UIWebView inside UIView programmatically

做~自己de王妃 提交于 2019-12-22 00:53:40

问题


I have a UITableView and I want to add a UIView as a footer. This UIView has a UIWebView and a UIButton. I have the following code:

- (void)viewWillAppear:(BOOL)animated {
CGRect frame = CGRectMake(10, 0, 280, 400);
self.webViewContent = [[UIWebView alloc] initWithFrame:frame];
self.webViewContent.delegate = self;
self.webViewContent.hidden = YES;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
UIView *viewA = [[UIView alloc] initWithFrame:CGRectMake(webView.bounds.origin.x, webView.bounds.origin.y, webView.bounds.size.width+20, webView.bounds.size.height + firstFrameY)];
viewA.backgroundColor = [UIColor yellowColor];
[viewA addSubview:self.webViewContent];
[viewA addSubview:linkButton];

[self.emailDetailsTableView setTableFooterView:viewA];
}

The output is that I can see everything except the UIWebView. However, if I test the following code

- (void)webViewDidFinishLoad:(UIWebView *)webView {
UIView *viewA = [[UIView alloc] initWithFrame:CGRectMake(webView.bounds.origin.x, webView.bounds.origin.y, webView.bounds.size.width+20, webView.bounds.size.height + firstFrameY)];
viewA.backgroundColor = [UIColor yellowColor];
//[viewA addSubview:self.webViewContent];
[viewA addSubview:linkButton];

[self.emailDetailsTableView setTableFooterView:self.webViewContent];
}

I can see the UIWebView. Please note that I commented the line where I was adding the UIWebView to the UIView. If I uncomment the line, I don't see the UIWebView!!!

Any ideas concerning what I'm doing wrong?

Thanks.


回答1:


It is likely that your UIWebView is already on screen somewhere. Indeed, if the webView is not displayed, its HTML is not rendered (like in off-screen rendering) and the webViewDidFinishLoading never called.

What I would try and do in your case is adding the viewA to the table footer and make the button hidden, if you need to show it only after the webView has loaded.

If you don't want the webView to occupy a large space in the footer while it is loading, make viewA small in the first place. When the HTML has loaded, change the view size (possibly according to the web page height, if it is ok for your app).

just a suggestion...



来源:https://stackoverflow.com/questions/6075055/uiwebview-inside-uiview-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!