2014-07-03 67 views
1

任何人都可以給我一個正確的方向,如何在iOS中創建自定義的UICollectionview單元格。我使用Objective C創建了一個應用程序,但使用Swift我無法做到。當我試圖運行我的申請,我收到以下錯誤: 「致命錯誤:無法解開Optional.None如何在iOS中使用Swift實現自定義UICollectionViewCell

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 
} 

如果有人提供任何教程鏈接,這將是非常有益的。提前致謝。

回答

4

最後我得到了我的問題的解決方案,我解釋我是如何解決這個下面,而不是使用 collectionView.registerClass使用:

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

現在它的正常工作就像一個魅力。

相關問題