【问题标题】:UICollectionViewCell dequeueReusableCellWithReuseIdentifier gives a hidden cellUICollectionViewCell dequeueReusableCellWithReuseIdentifier 给出一个隐藏单元格
【发布时间】:2016-01-07 23:39:27
【问题描述】:

我有一个 UICollectionView,我正在使用 dequeueReusableCellWithReuseIdentifier 重用单元格。第二次调用 cellForItemAtIndexPath 时,会返回一个隐藏的单元格 - 因此该单元格不会显示在我的 UICollectionView 中。我尝试将单元格硬编码为不被隐藏-但这不起作用,即使将隐藏属性设置为“否”,隐藏属性仍保持为“是”。是什么导致单元格被隐藏 - 以及如何否定?

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    SFReceiptCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    [cell setHidden:NO];

    NSLog(@"cell.hidden = %d", cell.hidden);
    ...

这显示在日志中:

cell.hidden = 1

没有代码是隐藏的单元格在哪里 - 所以我不知道是什么可能导致这种情况发生。

【问题讨论】:

  • 您是否为任何其他视图设置了隐藏?如果没有,您应该检查您的重用逻辑。
  • 同样的问题发生在我身上,你也解决了吗?

标签: ios uicollectionview uicollectionviewcell uicollectionviewlayout


【解决方案1】:

刚刚遇到同样的问题。我花了 3 个小时调试并尝试设置 .hidden = false 没有成功。 原来添加:

override func applyLayoutAttributes(layoutAttributes:UICollectionViewLayoutAttributes)
{
    super.applyLayoutAttributes(layoutAttributes)
    self.updateSubviews()
}

在我在项目中使用的UICollectionViewCell 子类中解决了这个问题。 我使用updateSubviews() 更新框架,因为我不想在单元格中使用自动布局。

【讨论】:

  • 更改单元格子视图框架的方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-02
  • 1970-01-01
相关资源
最近更新 更多