UIWebView问题

1.UIWebView内嵌在UITableView里,webview内容较少情况,在滚动到web view时,停顿一会滚动条消失,整个tableview就不能滚动问题。

解决办法:

            for (id subView in webView.subviews) {

                if ([subView isKindOfClass:[UIScrollView class]]) {

                    UIScrollView *scroll = (UIScrollView *)subView;

                    scroll.bounces = NO;

                }

            }

2. UIWebView内嵌在UITableView里,如何根据web view内容调整web view的高度以及cell的高度?

解决办法:

            UIWebView * webView =[[UIWebView alloc]initWithFrame:CGRectMake(0, 20, 320, 100)];

            webView.opaque = NO;

            webView.backgroundColor = [UIColor clearColor];

            webView.delegate = self;

在webview协议里添加如下代码:

- (void)webViewDidFinishLoad:(UIWebView *)webView

{

    CGSize actualSize = [webView sizeThatFits:CGSizeZero];

    CGRect newFrame = webView.frame;

    newFrame.size.height = actualSize.height;

    webView.frame = newFrame;

    NSString *string = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"];

    _webHeight = [string floatValue]+20;

   //调用以下方法更新tableview cell高度

    [self.tableView beginUpdates];

    [self.tableView endUpdates];

}

猜你喜欢

转载自zhy584520.iteye.com/blog/2097145