【发布时间】:2017-06-22 09:04:42
【问题描述】:
我正在开发 iOS 应用程序,但在使用 UICollectionView 单元格时遇到了一些问题。
这次想问一下UICollectionView(UICollectionReusableView)的section header如何显示
我已经实现了如下功能:
public func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
switch kind {
case UICollectionElementKindSectionHeader:
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "cellHeader", for: indexPath as IndexPath)
var labelHeader = headerView.viewWithTag(2) as! UILabel
if indexPath.section == 0 {
labelHeader.text = "Specialist Clinic"
}
else {
labelHeader.text = "Medical Support"
}
headerView.backgroundColor = UIColor.blue;
return headerView
default:
assert(false, "Unexpected element kind")
}
}
但是,它总是给出一个空白的结果。请看下面的屏幕截图
【问题讨论】:
-
您是否尝试过实现可重用的视图高度委托方法?
标签: ios swift xcode uicollectionview uicollectionreusableview