我的一个ViewControllers中有一个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
}
}
我真的希望这能帮上忙,否则我就再做一遍。。。
最佳答案
是否已从“集合”视图和“视图控制器”连接了代理和数据源,请输入image
关于ios - UICollectionView不显示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45557238/