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
}
}
确保您的numberOfSectionsInCollectionView:
压倒一切没有返回0
。
嗯,他返回'Array.count'其中2,但他没有填写单元格。 –
[“如果您未实现此方法,则集合视图使用默认值1.”](https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UICollectionViewDataSource_protocol/index。 html#// apple_ref/occ/intfm/UICollectionViewDataSource/numberOfSectionsInCollectionView :) –
@ThomasKilian他在部分项目上返回Array.count,而不是在集合中的部分。 –
您应该在'let cell = collectionView ....'后面填上内容' –
对不起,我忘了另外,我改变了单元格的颜色也尝试添加标签,但单元格不显示,它只是空白。 – redike
在故事板中设置了什么'itemSize'?此外,只是一个猜测,但在viewDidLoad帮助中添加'collectionView.reloadData()'? –