Swift:UICollectionView页脚没有显示

Max*_*ell 6 ios uicollectionview swift

我的UICollectionView的页脚没有显示任何子视图.我四处寻找答案,但似乎没有什么工作在我的情况下.我不确定它是否是Swift中的东西,或者我只是遗漏了一些东西.

在我的故事板中,我检查了该Section Footer框并在页脚视图中添加了几个按钮.我已将可重用标识符设置为footer并在视图控制器中将其注册为a.然后我打电话给collectionView(collectionView: UICollectionView!, viewForSupplementaryElementOfKind kind: String!, atIndexPath indexPath: NSIndexPath!)它设置了它.但是,当我运行应用程序时,页脚不会显示任何子视图(footer.subviews.count= 0).页脚的框架是正确的,但为什么我放在故事板中的子视图没有显示?

这是代码:

override func viewDidLoad() {
    ...
    uiCollectionView.registerClass(MyFooterView.classForCoder(), forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "footer")
}

func collectionView(collectionView: UICollectionView!, viewForSupplementaryElementOfKind kind: String!, atIndexPath indexPath: NSIndexPath!) -> UICollectionReusableView!  {
    let reusableView:MyFooterView = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionFooter, withReuseIdentifier: "footer", forIndexPath: indexPath) as MyFooterView
    println("Footer subivews: \(reusableView.subviews.count)") // 0
    return reusableView
}
Run Code Online (Sandbox Code Playgroud)

Ron*_*ler 2

尝试删除 registerClass 行:

uiCollectionView.registerClass(MyFooterView.classForCoder(), forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "footer")
Run Code Online (Sandbox Code Playgroud)

仅当您以编程方式创建视图/单元格时才使用 registerClass。如果您已在情节提要中创建了它,则 registerClass 将覆盖情节提要中的内容。