0

打我有问题,播放视频的采集观察室视频在多个小区

  1. 我的问题是我想只有在一个单元播放视频,但它在所有细胞发挥。
  2. 单元格包含视频和图像。
  3. 当数据源是图像的时候,我希望图像上的图像视图和视图必须隐藏起来。
  4. 当数据源是视频网址时,我希望图像在视图和图像视图必须隐藏。

我用下面的代码。

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 

//[self.collection reloadData]; 
homeceeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath]; 


UIImage *image; 
NSInteger row = [indexPath row]; 
NSURL *furl; 

NSLog(@"indexpath = %ld", (long)row); 

if ([app.array1[row] isKindOfClass:[NSURL class]]) 
{ 
     furl=app.array1[row]; 
    cell.movieplayer = [[MPMoviePlayerController alloc]initWithContentURL:app.array1[row]]; 

    cell.videoview.hidden=NO; 
    cell.img.hidden=YES; 
    cell.movieplayer.view.frame = cell.img.frame; 
    [cell.videoview addSubview:cell.movieplayer.view]; 

    NSLog(@"%@",cell.movieplayer); 
    [cell.movieplayer play]; 

      NSLog(@"%@",cell.movieplayer); 
} 
else { 
    if ([app.array1[row] isKindOfClass:[UIImage class]]) { 
     image= app.array1[row]; 
      cell.videoview.hidden=YES; 
    } 
    else { 
     image = [UIImage imageNamed:app.array1[row]]; 
      cell.videoview.hidden=YES; 

    } 

    cell.img.image = image; 
    cell.videoview.hidden=YES; 

} 

cell.text.text=[app.tarray1 objectAtIndex:indexPath.row]; 
return cell; 

}

  • app.array1是包含图像和视频的URL阵列。
  • cell.img是我在集合视图单元格中声明的图像视图。
  • cell.videoview是我在集合视图单元格中声明的视图。

请帮我解决这个问题,如果这个问题不明确离开我评论,我会为你的答案

回答

0

explain.Thanks创建UICollectionViewCell子类,那么你就应该重写prepeareForReuse方法 - 把电池默认模式并删除所有视频播放器的东西。在cellForItemAtIndexPath方法中使用你的子类。

斯威夫特

override func prepareForReuse() { 
    super.prepareForReuse() 

    //set cell to initial state here 
} 

Objective-C的

- (void) prepareForReuse 
{ 
    [super prepareForReuse]; 

    //set cell to initial state here 
} 

更多信息您可能会发现在UICollectionReusableView类引用。

执行任何必要的清理操作以准备再次使用该视图。

当视图出列使用时,在相应的出列方法将视图返回给您的代码之前调用此方法。子类可以覆盖此方法并使用它将属性重置为其默认值,并通常使视图可以再次使用。

+0

感谢您的答案,我想目标C我不知道迅速 –

+0

好了,只需一分钟... –

+0

WR我应该使用这个 –