2017-04-13 56 views
0

我正在显示的WebView的tableview细胞内,但是当我向上和向下滚动其显示相同的Web视图的多个的iOS - 实现代码如下多个显示器

请检查我下面的代码

videoHTML = [NSString stringWithFormat:@"\ 
        <html>\ 
        <head>\ 
             </head>\ 
        <body>\ 
        <iframe src=\"%@\" ></iframe>\ 
        </body>\ 
        </html>", videoURL]; 

UIWebView *videoView = [[UIWebView alloc] initWithFrame:self.view.frame]; 

ccell.backgroundColor=[UIColor redColor]; 

[ccell.contentView addSubview:videoView]; 

[videoView loadHTMLString:[videoHTML stringByReplacingOccurrencesOfString:@"\n" withString:@"<br/>"] baseURL:nil]; 

请困在这里4小时,现在怎么也找不到这个做

回答

0

如果使用ReusableCell,当你得到ReuseableCell,电池可能已经有一个videoView,又添加了另一个videoView。这将导致“其显示多个相同的Web视图”。

您可以检查单元格是否有videoView,或使用自定义单元格并添加UIWebView属性。

CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"CustomCellIdentifier"]; 

if (cell == nil) { 
    cell = [[CustomCell alloc] init]; 
    cell.videoView = [[UIWebView alloc] initWithFrame:self.view.frame]; 

    cell.backgroundColor=[UIColor redColor]; 

    [cell.contentView addSubview:cell.videoView]; 
} 

videoHTML = [NSString stringWithFormat:@"\ 
       <html>\ 
       <head>\ 
            </head>\ 
       <body>\ 
       <iframe src=\"%@\" ></iframe>\ 
       </body>\ 
       </html>", videoURL]; 


[cell.videoView loadHTMLString:[videoHTML stringByReplacingOccurrencesOfString:@"\n" withString:@"<br/>"] baseURL:nil];