我有這個簡單的代碼來控制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
}
}
您應該在'let cell = collectionView ....'後面填上內容' –
對不起,我忘了另外,我改變了單元格的顏色也嘗試添加標籤,但單元格不顯示,它只是空白。 – redike
在故事板中設置了什麼'itemSize'?此外,只是一個猜測,但在viewDidLoad幫助中添加'collectionView.reloadData()'? –