UITableViewCell内的UIWebView闪烁白色且大小不正确

时间:2013-06-13 14:44:06

标签: iphone ios uitableview uiwebview

这是我做的回购。

https://github.com/lifesaglitch/UIWebViewFlashWhite

基本理念是:

我有一个可扩展的表视图,有2个单元格:标题单元格和内容单元格。

单击标题单元格时,我插入一个内容单元格,并将html字符串加载到Web视图,该视图是内容单元格的子视图。

如果是第一次展开单元格,则Web视图会出现白色闪烁,框架大小正确。随后的扩展也可能有闪存,但帧大小是错误的。

我所尝试的(在项目中)是将颜色设置为clear,这不起作用。我还尝试了一个webview的委托,在加载html字符串后设置hidden = NO,但有时不调用委托回调。也许这是因为可重复使用的机制。

请从上面链接下载我的项目并试用。

以下是一些示例代码:

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];

    if (self) {

        self.backgroundColor = [UIColor clearColor];

        self.contentView.backgroundColor = [UIColor clearColor];

    }

    return self;
}

数据源方法:

    ContentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ContentCell"];
    [cell.contentView loadHTMLString:@"<html><body style='background-color: #ff0000'>this is contentasdoifjoiwjeofiqjweoifjqopweifj </body></html>" baseURL:nil];

编辑:

我已经提交了一个新版本:使用占位符首先隐藏webview,并在加载时取消隐藏它,但仍然有白色闪屏。

1 个答案:

答案 0 :(得分:2)

首先,您需要将展开/折叠动画修改为HeaderView,例如Apple samplethis tutorial

然后,您需要修改ContentCell.h和ContentCell.m中的代码  不要将contentView属性与其他IBOutlet(您的视图)挂钩     拖到tableCell后将是它的一个子视图。 SupperView和     Subview具有相同的名称可能导致崩溃。选择cellWebView名称并与您的UIWebView挂钩:

- (void)awakeFromNib{
    self.backgroundColor = [UIColor clearColor];
    [self.contentView setBackgroundColor:[UIColor clearColor]];
    [self.cellWebView setOpaque:NO];//Need to clear background of UIWebView
    self.cellWebView.backgroundColor = [UIColor clearColor];
}
相关问题