【发布时间】:2023-03-15 01:21:01
【问题描述】:
我想制作集合视图标题,但它不起作用。
故事板
在设备上
我下面的代码不起作用,print("ssssss") 不显示。
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
print("sssssss")
switch kind {
case UICollectionElementKindSectionHeader:
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind,
withReuseIdentifier: "mypageheader",
for: indexPath) as! MyPageHeaderView
headerView.backgroundColor = UIColor.blue;
return headerView
default:
assert(false, "Unexpected element kind")
}
}
关于 viewDidLoad()
self.collectionView?.register(MyPageViewController.self,forSupplementaryViewOfKind: UICollectionElementKindSectionHeader,withReuseIdentifier: "mypageheader")
【问题讨论】:
-
你不应该改用
register(MyPageHeaderView.self;...吗? -
是的,他应该... :)