簡體   English   中英

如何在iOS中使用Swift實現自定義UICollectionViewCell

[英]How to implement Custom UICollectionViewCell using Swift in iOS

誰能給我正確的方向,如何在iOS中創建自定義UICollectionview單元。 我使用Objective C創建應用程序時使用了相同的概念,但是使用Swift我還是無法做到這一點。 在嘗試運行應用程序時,出現以下錯誤:“ 致命錯誤:無法解包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")

現在,它像魅力一樣運轉良好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM