2017-04-13 78 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];