w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Embedding images from array in cells of Collection view

This code use as much of your code as as I could. You can compare line by line. I did't have your image assets or object array. This is all programmatic. Let me know if you need more help.

import UIKit


class ViewController: UIViewController, UICollectionViewDataSource,
UICollectionViewDelegate {

    var PastObjectsCollection:UICollectionView?
    var layout:UICollectionViewFlowLayout?

    override func viewDidLoad() {
        super.viewDidLoad()


        SetupCollectionView()
    }


    func SetupCollectionView() {
        self.layout = UICollectionViewFlowLayout()
        self.layout!.sectionInset = UIEdgeInsets(top: 10, left: 10, bottom:
10, right: 10)
        self.layout!.itemSize = CGSize(width: 90, height: 90)
        self.PastObjectsCollection = UICollectionView(frame: CGRect(x: 16,
y: 229, width: 368, height: 368), collectionViewLayout: layout!)
        self.PastObjectsCollection!.dataSource = self
        self.PastObjectsCollection!.delegate = self
       
self.PastObjectsCollection!.registerClass(UICollectionViewCell.self,
forCellWithReuseIdentifier:"Chow Object Reuse ID")
        self.PastObjectsCollection!.backgroundColor = UIColor.blackColor()
        self.view.addSubview(self.PastObjectsCollection!)

    }

    func numberOfSectionsInCollectionView(collectionView: UICollectionView)
-> Int {
        return 1
    }

    func collectionView(collectionView: UICollectionView,
numberOfItemsInSection section: Int) -> Int {
        return 1 //objectsCount
    }

    func collectionView(collectionView: UICollectionView,
cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell =
collectionView.dequeueReusableCellWithReuseIdentifier("Chow Object Reuse
ID", forIndexPath: indexPath) as UICollectionViewCell
        cell.backgroundColor = UIColor.whiteColor()
        var imageView:UIImageView = UIImageView()
        imageView.frame = CGRect(x: 0, y: 0, width: 90, height: 90)
        //imageView.image = imageThumbsArray[indexPath.row]
        cell.addSubview(imageView)
        return cell
    }
}




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.