Shm*_*idt 6 uicollectionview uicollectionviewdelegate ios7.1 swift
如何仅为一个部分显示页脚视图?
正如我发现的那样,我无法通过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
}
Run Code Online (Sandbox Code Playgroud)
mat*_*att 15
你不能传递nil到其他页脚视图,但你可以给其他页脚视图零高度,这相同的东西 - 它们将不会出现,因为它们没有高度.
所以实现collectionView:layout:referenceSizeForFooterInSection:给所有页脚一个零高度,除了你真正想要看到的那个.
| 归档时间: |
|
| 查看次数: |
4011 次 |
| 最近记录: |