简体   繁体   English

UIView内的UIWebView以编程方式

[英]UIWebView inside UIView programmatically

I have a UITableView and I want to add a UIView as a footer. 我有一个UITableView ,我想添加一个UIView作为页脚。 This UIView has a UIWebView and a UIButton . UIView具有一个UIWebView和一个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 . 输出是我可以看到除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 . 我可以看到UIWebView Please note that I commented the line where I was adding the UIWebView to the UIView . 请注意,我注释了将UIWebView添加到UIView的那一行。 If I uncomment the line, I don't see the UIWebView !!! 如果取消注释该行,则看不到UIWebView

Any ideas concerning what I'm doing wrong? 关于我在做什么错的任何想法吗?

Thanks. 谢谢。

It is likely that your UIWebView is already on screen somewhere. 您的UIWebView可能已经在屏幕上的某个位置。 Indeed, if the webView is not displayed, its HTML is not rendered (like in off-screen rendering) and the webViewDidFinishLoading never called. 实际上,如果未显示webView,则不会呈现其HTML(如在屏幕外渲染中), webViewDidFinishLoading永远不会调用webViewDidFinishLoading

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. 在您的情况下,我想尝试做的是将viewA添加到表页脚中,并使该按钮隐藏,如果只需要在webView加载后才显示它。

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. 如果您不希望webView在加载时在页脚中占据较大空间,请首先将viewA缩小。 When the HTML has loaded, change the view size (possibly according to the web page height, if it is ok for your app). 加载HTML后,更改视图大小(如果适合您的应用,则可能根据网页的高度)。

just a suggestion... 只是一个建议...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM