Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

collectionView:cellForItemAtIndexPath: why my view has zero subviews?

Please consider the following code:

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("DataItemCell", forIndexPath: indexPath) as DataItemCollectionViewCell

    println("\(cell.parametersView.subviews.count)")

    return cell
}

and the view hierarchy of the cell:

view hierarchy

I can't figure out why output is 0.

What I'm trying to achieve is to recursively loop through all descendants of parametersView.

like image 825
Andrey Gordeev Avatar asked Nov 18 '14 13:11

Andrey Gordeev


1 Answers

I try to simulate a similar project and I had the same issue (my prototype cell wasn't used). Be sure that you don't have any

    self.collectionView.registerClass(UICollectionViewCell, forCellWithReuseIdentifier: reuseIdentifier)

or

    self.collectionView.registerClass(DataItemCollectionViewCell, forCellWithReuseIdentifier: "DataItemCell"DataItemCollectionViewCell)

anywhere in your code.

Usually, there is one in the func viewDidLoad() function.

Edit:

Send me an exemple by mail, if you still have the problem.

like image 165
Florian Avatar answered Sep 21 '22 23:09

Florian