我有这个简单的代码来控制Collection视图,但它没有显示任何单元格。该应用程序有效,但它是空白的。标识符与单元格标识符匹配,类附加到集合视图。 我认为问题在于上调:as! UICollectionViewCell
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
}
}
答案 0 :(得分:0)
可能您忘记从故事板中检查作为初始视图控制器选项...
在标题下方的查看控制器下的右侧面板中,有一个复选框作为初始视图控制器,勾选此项,然后尝试运行... < / p>
答案 1 :(得分:-1)
确保您的覆盖numberOfSectionsInCollectionView:
未返回0
。