Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cells not appearing in UICollectionView?

I have a UICollectionViewController in a storyboard which has been linked to a file called XCollectionViewController.swift which is a subclass of UICollectionViewController.

My code is as follows:

super.viewDidLoad()
    // Register cell classes
    self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
}


    override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
    //#warning Incomplete method implementation -- Return the number of sections
    return 4
}


override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    //#warning Incomplete method implementation -- Return the number of items in the section
    return 10
}

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! UICollectionViewCell

    // Configure the cell

    return cell
}

I have the reuse identifier for the cell set as it is named in the file.

On run I can see the background of the CollectionView, but not the 40 Cells I should be seeing. What is wrong?

like image 610
DCIndieDev Avatar asked May 23 '15 16:05

DCIndieDev


1 Answers

Simply delete this line in viewDidLoad method would show your 40 cells.

self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
like image 63
tounaobun Avatar answered Sep 21 '22 23:09

tounaobun