【发布时间】:2017-06-30 09:23:41
【问题描述】:
我有一个 UICollectionView,它有节页眉,但没有节页脚。因此,我没有定义的页脚视图。
Apple's documentation 声明 You must not return nil from this method.
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
switch kind {
case UICollectionElementKindSectionHeader:
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind,
withReuseIdentifier: "MyHeaderView",
for: indexPath) as! MyHeaderView
switch indexPath.section
{
case 0:
headerView.label_title.text = "SOME HEADER"
case 1:
headerView.label_title.text = "ANOTHER HEADER"
default:
headerView.label_title.text = "UNKNOWN HEADER"
}
return headerView
default:
assert(false, "Unexpected element kind") // Not a good idea either
}
return nil // NOPE, not allowed
}
【问题讨论】:
-
这样返回空的UICollectionReusableView()
-
@Dharma NOPE,它会崩溃!
标签: ios swift uicollectionview