gpt4 book ai didi

ios - UICollectionViewCell dequeueReusableCellWithReuseIdentifier 给出一个隐藏的单元格

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:13:01 25 4
gpt4 key购买 nike

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

- (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

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

最佳答案

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

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

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

关于ios - UICollectionViewCell dequeueReusableCellWithReuseIdentifier 给出一个隐藏的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34667169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com