UICollectiveViewCell中的UIView无法隐藏

问题描述:

我得到了一个UICollectionView,它是以编程方式创建的。我想有一个集合视图在以下方向的行为:UICollectiveViewCell中的UIView无法隐藏

  1. 用户触摸细胞
  2. 隐藏的UIView覆盖图像
  3. 用户触摸细胞再次
  4. 显示的UIView以覆盖图像

1)之前在小区内的用户触摸图像看起来像这样

http://upload.siamza.com/1811355

2)后在小区内的用户触摸图像就会看起来像这样

http://upload.siamza.com/1811359

3)如果用户触摸图像再次它会看起来像1)

现在我的选择和取消是这个样子:

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(collectionView == genrescollectView){ 

    genresRecCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"genresRecCell" forIndexPath:indexPath]; 

     cell.checkforselectView.hidden = FALSE; 

    } 
} 

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(collectionView == genrescollectView){ 

    genresRecCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"genresRecCell" forIndexPath:indexPath]; 
     cell.checkforselectView.hidden = TRUE; 

    } 
} 

,但看到在

不工作

cell.checkforselectView.hidden = FALSE;

and

cell.checkforselectView.hidden = TRUE;

我已经通过添加 cell.checkforselectView.hidden = FALSE检查cellForItemAtIndexPath是否工作。

,它工作,所以我不知道任何人都可以帮我解决这个问题,这是现在在cellForItemAtIndexPath

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

     genresRecCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"genresRecCell" forIndexPath:indexPath]; 
     NSString *imageGenres = [genresData objectAtIndex:indexPath.row]; 
     cell.genresImage.image = [UIImage imageNamed:imageGenres]; 
     NSString *textToParse = imageGenres; 
     NSArray *components = [textToParse componentsSeparatedByString:@"."]; 
     NSString *genresText = [components firstObject]; 
     cell.labelGenres.text = genresText; 
     cell.genresImage.layer.cornerRadius = 10.0f; 
     cell.genresImage.layer.masksToBounds = YES; 

     //---------> this is where I check whether it work or not(and it work). 
     cell.checkforselectView.hidden = FALSE; 

     return cell; 

} 

预先感谢:)

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 

使用

[collectionView cellForItemAtIndexPath:indexPath]

而不是离开新单元

+0

非常感谢你,现在它的工作! – 2015-03-09 11:00:23

+0

我一直在梳理网络4个小时寻找类似问题的解决方案,这也解决了我的问题,谢谢! – pricetag 2015-12-27 21:36:55