微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

swift – 单元格没有出现在UICollectionView中?

我在故事板中有一个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)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐