ios – 集合视图单元格不显示

前端之家收集整理的这篇文章主要介绍了ios – 集合视图单元格不显示前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想显示尽可能多的collectionViewCells与按钮,因为我的数组中有字符串.但是当我启动模拟器时,只有CollectionView的背景,没有显示单元格.什么可能是错误

以下是我在CollectionViewController中附加到main.storyboard中的CollectionView的代码

  1. class CollectionViewController: UICollectionViewController {
  2.  
  3. var Array = [String]()
  4.  
  5. override func viewDidLoad() {
  6. super.viewDidLoad()
  7. // Do any additional setup after loading the view,typically from a nib.
  8.  
  9. Array = ["1","2","3","4","5"]
  10. }
  11.  
  12. override func didReceiveMemoryWarning() {
  13. super.didReceiveMemoryWarning()
  14. // Dispose of any resources that can be recreated.
  15. }
  16.  
  17. func collectionView(collectionView: UICollectionView,numberOfItemsSection section: Int) -> Int {
  18. return Array.count
  19. }
  20.  
  21. override func
  22. collectionView(collectionView: UICollectionView,cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
  23.  
  24. var cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell",forIndexPath: indexPath) as! UICollectionViewCell
  25.  
  26. var button = cell.viewWithTag(1) as! UIButton
  27. button.titleLabel?.text = Array[indexPath.row]
  28.  
  29. return cell
  30. }

}

这些是Collection View Controller的连接:

故事板上的视图控制器:

解决方法

您是否将CollectionViewController设置为故事板身份检查器?

猜你在找的iOS相关文章