UIWebView内置在UIView中 [英] UIWebView inside UIView programmatically

查看:50
本文介绍了UIWebView内置在UIView中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITableView,我想添加一个UIView作为页脚.此UIView具有UIWebViewUIButton.我有以下代码:

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

输出是我可以看到除UIWebView以外的所有内容. 但是,如果我测试以下代码

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

我可以看到UIWebView.请注意,我注释了将UIWebView添加到UIView的行.如果取消注释该行,则看不到UIWebView !!!

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?

谢谢.

推荐答案

您的UIWebView可能已经出现在屏幕上的某个位置.实际上,如果未显示webView,则不会呈现其HTML(如在屏幕外呈现中),并且webViewDidFinishLoading不会调用.

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.

在您的情况下,我想尝试做的是将viewA添加到表格页脚并将按钮隐藏,如果只需要在加载 后显示它,则该按钮将隐藏.

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.

如果您不希望webView在页脚加载时占据较大的空间,请首先将viewA缩小.加载HTML后,更改视图大小(如果您的应用程序可以,则根据网页高度来更改).

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).

只是一个建议...

这篇关于UIWebView内置在UIView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆