swift – 单元格没有出现在UICollectionView中?
发布时间:2020-12-14 05:38:29 所属栏目:百科 来源:网络整理
导读:我在故事板中有一个UICollectionViewController,它已链接到一个名为XCollectionViewController. swift的文件,该文件是UICollectionViewController的子类. 我的代码如下: super.viewDidLoad() // Register cell classes self.collectionView!.registerClass(
我在故事板中有一个UICollectionViewController,它已链接到一个名为XCollectionViewController.
swift的文件,该文件是UICollectionViewController的子类.
我的代码如下: super.viewDidLoad() // Register cell classes self.collectionView!.registerClass(UICollectionViewCell.self,forCellWithReuseIdentifier: reuseIdentifier) } override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { //#warning Incomplete method implementation -- Return the number of sections return 4 } override func collectionView(collectionView: UICollectionView,numberOfItemsInSection section: Int) -> Int { //#warning Incomplete method implementation -- Return the number of items in the section return 10 } override func collectionView(collectionView: UICollectionView,cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier,forIndexPath: indexPath) as! UICollectionViewCell // Configure the cell return cell } 我有单元格的重用标识符,因为它在文件中命名. 在运行中,我可以看到CollectionView的背景,但不是我应该看到的40个单元格.怎么了?
只需在viewDidLoad方法中删除此行即可显示您的40个单元格.
self.collectionView!.registerClass(UICollectionViewCell.self,forCellWithReuseIdentifier: reuseIdentifier) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |