【发布时间】:2017-08-07 23:49:35
【问题描述】:
我的一个 ViewController 中有一个 UICollectionView,但它根本不显示。我不知道为什么会这样。我已经为我拥有的两种不同类型的单元格以及 CollectionView 的所有其他代码编写了代码,但它不起作用。
如果你们需要任何类型的信息,我很乐意提供给你们,但我不会马上做,因为有很多地方可能会出现问题,所以我不会将立即发布所有内容。希望你能理解。
仅供参考:我的代码是用 swift 3 编写的,您知道,我已经尝试清理我的项目并将 CollectionView 与代码断开连接,然后重新连接。
非常感谢
我真的需要你的帮助,因为我不知道为什么会这样。
好吧,代码如下:
class AddPersonViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UICollectionViewDelegate, UICollectionViewDataSource, APCodeCollectionCellDelegate {
然后有一些东西介于两者之间,还有网点
这里我设置了数据源和委托
collectionView.delegate = self
collectionView.dataSource = self
这里我做了一些自定义
collectionView.layer.borderColor = UIColor(red: 2/255, green: 11/255, blue: 57/255, alpha: 1.0).cgColor
collectionView.layer.borderWidth = 2
collectionView.layer.cornerRadius = 15
collectionView.clipsToBounds = true
最后是数据源的所有代码
//Collection View Cells
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return person.codes.count + 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.row < self.person.codes.count {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CodeCell", for: indexPath) as! APCodeCollectionViewCell
cell.codeTextView.text = person.codes[indexPath.row].code
cell.nameLabel.text = person.codes[indexPath.row].title
cell.isFavorite = person.codes[indexPath.row].favorite
cell.codeTextView.layer.cornerRadius = 15
cell.layer.cornerRadius = 4
cell.backgroundColor = UIColor.white
cell.delegate = self
return cell
} else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AddCell", for: indexPath) as! APAddCodeCollectionViewCell
cell.layer.cornerRadius = 4
cell.backgroundColor = UIColor.white
return cell
}
}
我真的希望这会有所帮助,否则我会重新做一遍......
【问题讨论】:
-
你设置了collectionview的delegate和datasource了吗??
-
检查数据源和委托是否提供,其次查看用于集合视图的数组不能为 nil
-
需要看码友:D
-
我已经添加了代码
标签: ios swift swift3 uicollectionview xcode8