DrWhat
DrWhat

Reputation: 2490

Cell not displayed in collection view instantiated from storyboard (not embedded)

In the below scenario, I cannot get even the cell background (black) to show.

In a storyboard, I've a container with an embedded custom UICollectionView with a custom UICollectionViewCell with an image view as an outlet. In another View Controller, I've inserted a container where I want the same collection view and cell.

storyboard

I seem to be able to instantiate the custom collection view and the cell (both print to console and don't return nil). The following code prints as below.

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
    print("into the collectionView")
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("photoCell" , forIndexPath: indexPath) as! PhotoCollectionViewCell

    cell.backgroundColor = UIColor.blackColor()
    let myRect = CGRect(x: 0, y: 0, width: 78, height: 78)
    cell.frame = myRect

    cell.autoresizesSubviews = false

    if let imageForCell = images?[indexPath.row]
    {
        cell.cellImageView.image = imageForCell
        print("cell image \(cell.cellImageView.image)")
    }
    print(cell.cellImageView?.bounds.size)
    cell.cellImageView?.layer.borderWidth = 1.0
    cell.cellImageView?.layer.borderColor = UIColor.blackColor().CGColor

    return cell
}

into the collectionView

cell image Optional(, {320, 213})

Optional((78.0, 78.0))

I've tried every suggested solution, but can't get the cell to show within the collection view.

Upvotes: 1

Views: 371

Answers (1)

Saood
Saood

Reputation: 283

embed controller with both container. so whatever you will do in controller then it will be reflected on both container

storyBoard

Upvotes: 1

Related Questions