【发布时间】:2018-08-07 09:40:31
【问题描述】:
我对 Swift 很陌生。我的问题是我的UICollectionView 正在消失。
在Xcode 中,它显示一切就绪,但是当我在模拟器或设备上启动时,它只剩下导航栏和标签栏消失。
有谁知道是什么原因造成的或如何解决这个问题? 干杯!
这是我的代码:
类用户:UICollectionViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func numberOfSections(in collectionView: UICollectionView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 0
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of items
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! UserHeaderView
header.userEmail.text = PFUser.current()!.email
header.userChosenName.text = PFUser.current()!.object(forKey: "nickname") as? String
header.profilePicture.layer.cornerRadius = header.profilePicture.frame.size.width/2
header.profilePicture.clipsToBounds = true
let query = PFUser.current()?.object(forKey: "profilePicture") as! PFFile
query.getDataInBackground { (image, error) in
if error == nil {
header.profilePicture.image = UIImage(data: image!)
}
else {
SVProgressHUD.showError(withStatus: "Something's Wrong...")
}
}
return header
}
【问题讨论】:
-
在这里分享您的代码,我们可以解决问题
-
您是否为设计的每个项目设置了自动布局??
-
您在 numberOfItemsInSection 和 numberOfSections 中返回 0 个项目,这就是您没有显示任何单元格的原因
-
您将从 numberOfItemsInSection 和 numberOfSections 返回一些数字,然后您将能够看到单元格或 headerView
-
@MaheshDangar 这是我的代码,请看一下。干杯!
标签: ios swift xcode uicollectionview