【问题标题】:UICollectionView show footer only for the last sectionUICollectionView 仅显示最后一部分的页脚
【发布时间】:2014-12-31 17:51:39
【问题描述】:

如何仅显示一个部分的页脚视图?

我发现,我不能通过nil 来隐藏其他部分的页脚视图,因为它会导致崩溃。

override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {

        var v : UICollectionReusableView! = nil
        if kind == UICollectionElementKindSectionHeader {
            let x = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionHeader, withReuseIdentifier:reuseHeaderIdentifier, forIndexPath:indexPath) as HouseNameReusableView

            let h = houses[indexPath.section]        
            x.nameLabel.text = h["name"] as? String

            return x

        }else if kind == UICollectionElementKindSectionFooter {
            if indexPath.section == houses.count - 1{
            let x = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionFooter, withReuseIdentifier:reuseFooterIdentifier, forIndexPath:indexPath) as FooterCollectionReusableView

            return x
            }
        }
        return v
    }

【问题讨论】:

    标签: swift uicollectionview ios7.1 uicollectionviewdelegate


    【解决方案1】:

    您不能将nil 传递给其他页脚视图,但您可以将其他页脚视图设为零高度,这相当于同一件事 - 它们不会出现,因为它们没有高度.

    所以实现collectionView:layout:referenceSizeForFooterInSection: 将所有页脚的高度设为零,除了您真正想看到的页脚。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-03
      • 1970-01-01
      • 1970-01-01
      • 2018-10-23
      • 2013-11-18
      • 1970-01-01
      相关资源
      最近更新 更多