向上滚动

时间:2016-05-19 08:17:01

标签: ios objective-c iphone uitableview uicollectionviewcell

我正在尝试创建一个tableviewcell collectionview,其中collectionviewcell具有自定义tableviewcell。 我创建了一个具有自定义collectionview的控制器。 TableViewCell嵌入了collectioncell。现在,我使用图片文字创建了自定义collectionViewcell

collectionviewcell中,第4张图像需要是半透明的,所以当我在 cellforitematindex 中渲染图像时,我会使图像保持半透明。它完全正常工作,直到我向下滚动桌面视图。向上滚动后,第一张图像变成半透明。

我在网上看到I have tableviewcell class. I have collectionviewcell class. 正在重复使用,可能是第一个在第一个位置重复使用,第一个位置获得半透明图像

我有一个控制器类,它是 tableviewcell collectionviewcell 的数据源和委托。

collectionviewcell

现在我得到一个解决这个问题的链接,它说你必须继承你的imageview并添加一些方法,这些方法每次都会imageview为零,并且会创建一个新的I have a subclass of collectionviewcell : uicollectionviewsubclass 。< / p>

Link for the above

所以我创建了一个collectionviewcell子类

cellForRowAtIndexPath

在我的控制器中,首先我重用tablecell

所以我创建了一个控制器让我们说: -

mycontroller并添加了一个tableview,我添加了一个自定义的tableviewcell, 在self.collectionview = [self.contentView viewWithTag:tagno]; 我dequeueReusableCellWithIdentifier,所以我的tableviewcell将会来。现在,在我的tableViewcell .m文件中,我为collectionview创建了一个插座,并使用标签I make

collectionview
  

此标记是collectionviewcell tagno

现在我在tableviewcell课程中注册了collectionview,它有[self.collectionview registerClass:[uicollectionviewsubclass class] forCellWithReuseIdentifier:@"reuseidentifier"];的出口

collectionviewcell

在我的imageview中,我有uicollectionviewsubclass *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"reuseidentifier" forIndexPath:indexPath]; 个出口和其他商店

当我创建子类时,我创建了如链接中所述。

然后在我的控制器 cellForItemAtIndexPath collectionview

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

     ImageCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"ImageCell" forIndexPath:indexPath];
    cell.ImageCellView.image  = [UIImage imageWithData: imageData];
    if (indexPath.row == 3) {
            cell.grayViewImage.hidden = FALSE;
    }
    return cell;
}

但是这个单元格是一个子类化的单元格,没有图像视图的出口(whihc在collectionview类中) 所以它在self中显示imageView,因为nil没有实例化。

grayViewImage
  

<button type="submit" id="btnSaveChanges" onclick="location.href'@Url.Action("BestuuurEdit", "UpdatePersoon")'" value="Wijzigen" class="btn btn-primary">Wijzigen</button> 是一个uiview,我制作隐藏的虚假来制作单元格   半透明

可能是什么原因。

2 个答案:

答案 0 :(得分:2)

要解决此问题,您应准备好重复使用的单元格。对prepareForReuseUICollectionViewCell使用名为UITableViewCell的方法。 像这样实现并在cellForItemAtIndexPath

中调用它
- (void)prepareForReuse 
{
    yourImageView .image = nil;
    [super prepareForReuse];
}

答案 1 :(得分:0)

我的代码中存在差距:

简单:你错过了其他部分见下文:

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

             ImageCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"ImageCell" forIndexPath:indexPath];
            cell.ImageCellView.image  = [UIImage imageWithData: imageData];
            if (indexPath.row == 3) {
                    cell.grayViewImage.hidden = FALSE;
            }else{
    cell.grayViewImage.hidden = TRUE;
    }
            return cell;
        }

谢谢!

相关问题