gpt4 book ai didi

ios - 如何在 iOS 中使用 Swift 实现自定义 UICollectionViewCell

转载 作者:搜寻专家 更新时间:2023-11-01 06:24:41 25 4
gpt4 key购买 nike

谁能给我一个正确的方向,如何在 iOS 中创建自定义 UICollectionview 单元格。我已经使用 Objective C 创建了一个应用程序,但使用 Swift 我无法做到这一点。当我尝试运行我的应用程序时,出现以下错误:“ fatal error :无法展开 Optional.None

func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell!
{
var cell = collectionView?.dequeueReusableCellWithReuseIdentifier("CustomsCollectionViewCell", forIndexPath: indexPath) as CustomsCollectionViewCell
var values = String(indexPath.row)
cell.lblTextDisplay.text = values **//// I got error in this line ////**

return cell
}

如果有人提供任何教程链接,那将非常有帮助。提前致谢。

最佳答案

我终于找到了问题的解决方案,我在下面解释了我是如何解决这个问题的,而不是使用collectionView.registerClass 使用:

let nibName=UINib(nibName: "CustomsCollectionViewCell", bundle:nil)
self.collectionView.registerNib(nibName, forCellWithReuseIdentifier: "CustomsCollectionViewCell")

现在一切正常。

关于ios - 如何在 iOS 中使用 Swift 实现自定义 UICollectionViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24550137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com