我需要的是一个底脚高度为50的背景颜色为黑色。而已。暂时忘记下面的实现,让我知道您将如何实现。
我正在使用以下内容:
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let view = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "FooterView", for: indexPath as IndexPath)
// configure footer view
return view
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize
{
return CGSize(width: 375, height: 100)
}
但是,没有页脚附加到集合视图。我不明白为什么这不起作用以及我应该如何纠正。请帮我解决这个问题。
答案 0 :(得分:1)
我如何做:
1)创建自定义页脚类:
import UIKit
class BlackFooterView: UICollectionReusableView {
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .black
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
2)在UICollectionView
中注册页脚类并设置引用大小(通常在所需viewDidLoad
的{{1}}方法中:
ViewController
3)实现委托方法:
override func viewDidLoad() {
super.viewDidLoad()
/// Class registration
self.collectionView!.register(BlackFooterView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: footerReuseIdentifier)
/// Reference size
(self.collectionView.collectionViewLayout as! UICollectionViewFlowLayout).footerReferenceSize = CGSize(width: collectionView.bounds.width, height: 50)
}
NB:
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
if kind == UICollectionView.elementKindSectionFooter {
return collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: footerReuseIdentifier, for: indexPath)
}
/// Normally should never get here
return UICollectionReusableView()
}
类作为示例,这就是UICollectionViewController
方法从delegate
开始的原因答案 1 :(得分:1)
这是我的方式。我对此进行了测试,并且有效。
class ViewController: UIViewController, UICollectionViewDataSource {
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
collectionView.dataSource = self
}
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let view = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: "Footer", for: indexPath)
view.backgroundColor = .red
return view
}
}
答案 2 :(得分:-2)
select (some columns),q.trans_value,q.trans_id
from
(some tables and joins)
cross apply
(
select top 1 b.trans_value,b.trans_id
from table2 b
where b.no_member=a.no_member -- Here you add all "join conditions" with the external tables
order by b.trans_value desc,b.trans_id asc -- what if two transactions have same value?
)as q