【发布时间】:2020-06-11 13:01:26
【问题描述】:
我尝试使用集合视图委托方法viewForSupplementaryElementOfKind 在我的集合视图布局中添加页脚视图,但在重新加载集合视图时它没有被调用。
SeatArrangementViewController : UICollectionViewDelegate , UICollectionViewDataSource , QuiltViewDelegate ,UICollectionViewDelegateFlowLayout {
override func viewDidLoad() {
super.viewDidLoad()
setCollection()
}
func setCollection() {
self.clnSeats.collectionViewLayout.invalidateLayout()
self.clnSeats.register(UINib(nibName: "SeatFooterView",bundle:nil),forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "SeatFooterView")
let space = UIScreen.main.bounds.size.width - 262
self.clnSeats.contentInset = UIEdgeInsets(top: 0, left: space/2.0, bottom: 90, right: space/2.0)
let layout = self.clnSeats.collectionViewLayout as! QuiltView
layout.scrollDirection = UICollectionViewScrollDirection.vertical
layout.itemBlockSize = CGSize(width: 50, height: 50)
self.clnSeats.reloadData()
}
集合视图方法
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
switch kind{
case UICollectionElementKindSectionFooter: .....
}
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, blockSizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
// get random width and height values for the cells
let width = self.numberWidths[indexPath.row]
let height = self.numberHeights[indexPath.row]
return CGSize(width: width, height: height)
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetsForItemAtIndexPath indexPath: IndexPath) -> UIEdgeInsets {
return UIEdgeInsets(top: 2, left: 2, bottom: 2, right: 2)
}
我还添加了@objc (collectionView:viewForSupplementaryElementOfKind:atIndexPath:),但这对我不起作用。
【问题讨论】:
-
请显示更多上下文。谢谢。
-
我更新问题@matt。它在实时应用程序中运行良好,但是当我今天运行此代码时,它会产生问题。
-
好吧,这不是真正的代码。
-
我只有这个代码。你能帮我看看这段代码有什么问题吗?
-
它不可能是你的真实代码。您尚未声明 SeatArrangementViewController 是 UIViewController。将您的真实代码复制并粘贴到问题中。
标签: ios swift xcode uicollectionview