简体   繁体   中英

How to implement Custom UICollectionViewCell using Swift in iOS

Can anybody give me a right direction on, how to create custom UICollectionview cell in iOS. I have worked the same concept using Objective C to create an app, but with Swift I can't able to make it though. While I tried to run my application, I am getting the following error : " fatal error: Can't unwrap 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
}

If anyone provides any tutorial link that would be very helpful. Thanks in advance.

Finally I got the solution for my problem, I am explaining how I resolved this below, instead of using collectionView.registerClass use:

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

Now it's working fine like a charm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM