collectionView:cellForItemAtIndexPath:为什么我的视图没有子视图?

And*_*eev 6 ios uicollectionviewcell swift

请考虑以下代码:

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

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

    return cell
}
Run Code Online (Sandbox Code Playgroud)

和单元格的视图层次结构:

查看层次结构

我无法弄清楚为什么输出0.

我想要实现的是递归循环遍历所有的后代parametersView.

小智 4

我尝试模拟一个类似的项目,但遇到了同样的问题(未使用我的原型单元)。确保您没有任何

    self.collectionView.registerClass(UICollectionViewCell, forCellWithReuseIdentifier: reuseIdentifier)
Run Code Online (Sandbox Code Playgroud)

或者

    self.collectionView.registerClass(DataItemCollectionViewCell, forCellWithReuseIdentifier: "DataItemCell"DataItemCollectionViewCell)
Run Code Online (Sandbox Code Playgroud)

代码中的任何位置。

通常,函数中有一个func viewDidLoad()

编辑:

如果您仍然遇到问题,请通过邮件给我发送一个示例。