我在导航控制器中嵌入了一个集合视图控制器,设置视图控制器从tabBar控制器切换到该导航控制器但是当我的集合视图控制器加载时它不会显示任何内容!这是我的代码
class HomeVC: UICollectionViewController, UINavigationControllerDelegate{
override func viewDidLoad() {
super.viewDidLoad()
collectionView?.backgroundColor = UIColor.white
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
return CGSize(width: self.view.frame.size.width, height: 220)
}
override func numberOfSections(in collectionView: UICollectionView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 0
}
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let header = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "header", for: indexPath) as! HeaderView
header.fullnameLbl.text = (PFUser.current()?.object(forKey: "name") as? String)?.capitalized
header.webTxt.text = PFUser.current()?.object(forKey: "web") as? String
header.webTxt.sizeToFit()
header.bioLbl.text = PFUser.current()?.object(forKey: "bio") as? String
header.bioLbl.sizeToFit()
header.button.setTitle("Edit Profile", for: .normal)
let avaQuery = PFUser.current()?.object(forKey: "ava") as! PFFile
avaQuery.getDataInBackground { (data, error) in
if let err = error{
print(err.localizedDescription)
return
}
if let imageData = data{
header.avaImg.image = UIImage(data: imageData)
}
}
return header
}
}
有人知道为什么会这样吗?在使用集合视图控制器时,我似乎总是遇到这个问题。