mercredi 24 juin 2015

Register collection view cells in table view cell

I have a table view cell with collection view in it. Collection view requires to register xibs of its own cells. I can't figure it out where should I place code for registering collection view cells xibs.

I tried to place it in awakeFromNib() and init(), but it doesn't work.

let photoCollectionViewCellID = "photoCollectionViewCellID"
let addPhotoCollectionViewCellID = "AddPhotoCollectionViewCell"

class PhotosTableViewCell: UITableViewCell {

    @IBOutlet weak var collectionView: DynamicCollectionView!

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {

        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        let nibName = UINib(nibName: photoCollectionViewCellID, bundle:nil)
        collectionView!.registerNib(nibName, forCellWithReuseIdentifier: photoCollectionViewCellID)
        //
        let nibName2 = UINib(nibName: addPhotoCollectionViewCellID, bundle:nil)
        collectionView!.registerNib(nibName2, forCellWithReuseIdentifier: addPhotoCollectionViewCellID)
    }

    required init(coder aDecoder: NSCoder) {
        super.init(coder:aDecoder)
        println("init photo cell")
    }

    func setCollectionViewDataSourceDelegate(dataSourceDelegate delegate: protocol<UICollectionViewDelegate,UICollectionViewDataSource>) {
        let nibName = UINib(nibName: photoCollectionViewCellID, bundle:nil)
        collectionView!.registerNib(nibName, forCellWithReuseIdentifier: photoCollectionViewCellID)

        let nibName2 = UINib(nibName: addPhotoCollectionViewCellID, bundle:nil)
        collectionView!.registerNib(nibName2, forCellWithReuseIdentifier: addPhotoCollectionViewCellID)

        collectionView.dataSource = delegate
        collectionView.delegate = delegate
        collectionView.reloadData()
    }
}

See more ..

Aucun commentaire:

Enregistrer un commentaire