I can not display an array of objects in a collectionview from an api. I can parse the data and I know my array has all the data I want. Am I missing a method here?
class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
@IBOutlet weak var collections: UICollectionView! @IBOutlet weak var theSearch: UISearchBar! var cPlayerArr = [CurrentPlayer]() override func viewDidLoad() { super.viewDidLoad() downloadJSON { self.collections.reloadData() //print("***\(self.cPlayerArr)***") } self.collections.delegate = self self.collections.dataSource = self }
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
print(cPlayerArr.count) return cPlayerArr.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "playercell", for: indexPath) as! CurrentPlayerCell let item = cPlayerArr[indexPath.row] print(cPlayerArr[0]) cell.update(with: item) return cell }