我想让一个UICollectionViewController显示一个单元格的网格(我将在稍后添加文本,如果可能的话可能为textViews)。我有:为什么我的UICollectionViewController不显示任何内容?
class GridViewController : UICollectionViewController{
//(NOW GONE) @IBOutlet weak var gridViewTable = UICollectionViewController()
let arr1 : [String] = []
let arr2 : [String] = []
override func viewDidLoad(){
super.viewDidLoad()
self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "gridCell")
}
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 4
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath as IndexPath)
cell.backgroundColor = UIColor.red
return cell
}
}
我用界面生成器来连接白色的单元格将转到gridViewTable。根本没有出现,即使它运行并编译。我怎样才能让细胞显示出来?
谢谢!只是好奇;为什么我的工作没有? – Derry
@Derry你不是覆盖已经包含在'UICollectionViewController'中的函数,你自己重新定义它们。当我第一次回答你的问题时,我错过了。 – Paolo
也在我的故事板上,我将TextView拖放到原型单元格中,因为我希望单元格填充从2D数组中拉出的文本。我怎样才能得到这些文字视图? – Derry