0
我必須在表格視圖單元格上播放視頻,但不希望重新使用視頻單元格,因爲它會再次重新創建視頻。停止重複使用視圖單元格的視圖
我試圖緩存數組中的單元格和從數組中加載(如果存在的話),但是當視圖彈出到前一個視圖時會造成一些問題。
即使視頻被刪除,視頻仍在播放。
AVTableViewCell *cachedCell = [self.cellList objectForKey:indexPath];
if (cachedCell) {
return cachedCell;
} else {
AVTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AVTableViewCell" forIndexPath:indexPath];
[cell configCell:indexPath];
return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (section == 1) {
[self.cellList setObject:(AVTableViewCell *)cell forKey:indexPath];
}
}
下面的代碼我在刪除視頻之前彈出視圖控制器,但仍然視頻或音頻播放某個時間。
- (IBAction)btnBackTapped:(id)sender {
// To Avoid the re-using video cell, implemented cache so make sure it got removed before going back to the previous screen.
AVTableViewCell *cachedCell = [self.cellList objectForKey:[NSIndexPath indexPathForRow:0 inSection:1]];
if (cachedCell)
{
if (cachedCell.isJWVideo) {
[cachedCell.player stop];
[cachedCell.player.view removeFromSuperview];
cachedCell.player = nil;
} else {
[cachedCell.ytPlayerView stopVideo];
[cachedCell.ytPlayerView clearVideo];
cachedCell.ytPlayerView = nil;
}
[self.cellList removeAllObjects];
self.cellList = nil;
}
[self.navigationController popViewControllerAnimated:YES];
}
是否有任何其他技術在表格視圖單元格上播放視頻而不重複使用?因爲當我做上下滾動時,它會阻止滾動視圖再次加載視頻。
感謝您的回覆。我已經嘗試過那部分,但是發生了什麼,它是在重新使用單元格時再次重新創建視頻,這意味着我必須等待看到已重新加載的視頻,因爲它已被刪除並重新加載。 ' - (void)prepareForReuse {super prepareForReuse];如果(self.isJWVideo){self.jwPlayer stop]; self.jwPlayer = nil;其他{ } [self.ytPlayerView stopVideo]; self.ytPlayerView = nil; } }' 你能告訴我上面的代碼有什麼問題嗎? – Jay
它看起來不錯,但我從這裏不能告訴。你有沒有看過使用'tableView:didEndDisplayingCell:forRowAtIndexPath:'停止視頻並刪除播放器?這是檢測何時從表格中移除細胞的官方方式。 – norders