不确定发生了什么。这可能是iOS 8上的collectionView错误吗?顶部的黑色不应该在那里......
查看控制器代码:
class SearchViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
@IBOutlet var collectionView: UICollectionView!
// MARK: - VC Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
var viewNib = UINib(nibName: "SearchFiltersCollectionReusableView", bundle: nil)
collectionView.registerNib(viewNib, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "filter")
var viewNib2 = UINib(nibName: "SearchResultCollectionViewCell", bundle: nil)
collectionView.registerNib(viewNib2, forCellWithReuseIdentifier: "searchCell")
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - CV Datasource
func numberOfSectionsInCollectionView(collectionView: UICollectionView!) -> Int {
return 2
}
func collectionView(collectionView: UICollectionView!, numberOfItemsInSection section: Int) -> Int {
var itemsCount = section == 1 ? 10 : 0
return itemsCount
}
func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell! {
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("searchCell", forIndexPath: indexPath) as UICollectionViewCell
return cell
}
// MARK: - CV Delegate
func collectionView(collectionView: UICollectionView!, viewForSupplementaryElementOfKind kind: String!, atIndexPath indexPath: NSIndexPath!) -> UICollectionReusableView! {
var section = indexPath.section
var identifier = indexPath.section == 0 ? "nav" : "filter"
var view = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionHeader, withReuseIdentifier: identifier, forIndexPath: indexPath) as UICollectionReusableView
return view
}
// MARK: - CV DelegateFlow
func collectionView(collectionView: UICollectionView!, layout collectionViewLayout: UICollectionViewLayout!, sizeForItemAtIndexPath indexPath: NSIndexPath!) -> CGSize {
var width = collectionView.bounds.size.width
return CGSizeMake(width, 70)
}
func collectionView(collectionView: UICollectionView!, layout collectionViewLayout: UICollectionViewLayout!, referenceSizeForHeaderInSection section: Int) -> CGSize {
var width = collectionView.bounds.size.width
var height : CGFloat = section == 0 ? 240.0 : 70.0
return CGSizeMake(width, height)
}
}
答案 0 :(得分:2)
尝试将视图控制器automaticallyAdjustsScrollViewInsets
属性设置为NO
。