Print coedata on a collection view cell label (swift4)

This code below prints all of the entries of coreData on a label.

var users = [User]()


    override func viewDidLoad() {
super.viewDidLoad()
if cdHandler.fetchObject() != nil {
 users = cdHandler.fetchObject()!

    for c in users {

        drj.text = "\((drj.text)!)+\((c.userName)!)"
    }

}

}
I want to do the same thing on a collection view cell label. I want to print a single entry on a collection view label in the collection view cell.

COLLECTIONVIEWCELL

  import UIKit

   class whyCollectionViewCell: UICollectionViewCell {
  @IBOutlet var general: UILabel!

      }

COLLECTIONVIEWVIEWCONTROLLER

 import UIKit

    class collectionVIEW: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {

    var users = [User]()
@IBOutlet var theIssues: UICollectionView!
override func viewDidLoad() {
    super.viewDidLoad()



}


func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {


}


func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {



}




    }

Hi @timswift

In the method ‘collectionView(_ collectionView: UICollectionView, cellForItemAt…’ you need to dequeue a reusable cell and set cell’s label text with your code data object.
Take a look at this tutorial, it explains how you need to set up a UICollectionView - https://www.raywenderlich.com/136159/uicollectionview-tutorial-getting-started

Hope this is helpful

Nikita

This topic was automatically closed after 166 days. New replies are no longer allowed.