swift 1.2 collection view

问题描述:

我有这个简单的代码来控制Collection视图,但它不显示任何单元格。该应用程序的作品,但它是空白的。标识符与单元格标识符相匹配,并且类将附加到集合视图。 我认为问题是与upcast:as! UICollectionViewCellswift 1.2 collection view

class CollectionViewController: UICollectionViewController { 
    var Array = ["one", "two"] 

    override func viewDidLoad() { 
     super.viewDidLoad() 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 

    } 
    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
      return Array.count 
    } 

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
     let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! UICollectionViewCell 
     return cell 
    } 
} 
+1

您应该在'let cell = collectionView ....'后面填上内容' –

+0

对不起,我忘了另外,我改变了单元格的颜色也尝试添加标签,但单元格不显示,它只是空白。 – redike

+0

在故事板中设置了什么'itemSize'?此外,只是一个猜测,但在viewDidLoad帮助中添加'collectionView.reloadData()'? –

确保您的numberOfSectionsInCollectionView:压倒一切没有返回0

+0

嗯,他返回'Array.count'其中2,但他没有填写单元格。 –

+0

[“如果您未实现此方法,则集合视图使用默认值1.”](https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UICollectionViewDataSource_protocol/index。 html#// apple_ref/occ/intfm/UICollectionViewDataSource/numberOfSectionsInCollectionView :) –

+0

@ThomasKilian他在部分项目上返回Array.count,而不是在集合中的部分。 –

可能是你忘了检查从故事板作为初始视图控制器选项...

enter image description here

在根据控制器标题下方查看右侧面板上,有一个复选框作为初始视图控制器,勾选此项,然后尝试运行...

+0

它是检查。 – redike

+0

你使用自己定制的CollectionviewCell类吗? –

+0

不,我不是,但我已经解决了,谢谢 – redike