【问题标题】:UICollectionview footer in swiftswift中的UICollectionview页脚
【发布时间】:2016-08-13 05:34:59
【问题描述】:

我想使用此代码将页脚添加到UICollectionView。我在 UICollectionView 布局中使用自定义布局

添加了委托和数据源方法:-

UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout

viewdDidLoad() 函数中的代码:-

 UINib(nibName: "ProfileFooter", bundle:nil)
 collectionView!.registerNib(nibName1, forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "ProfileFooter")
        collectionView.registerClass(ProfileFooter.classForCoder(), forSupplementaryViewOfKind: "ProfileFooter", withReuseIdentifier: "ProfileFooter")

 func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {

        var reusable = UICollectionReusableView()

            if kind == UICollectionElementKindSectionFooter{
                let ProfileFooter = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionFooter, withReuseIdentifier: "ProfileFooter", forIndexPath: indexPath)
                ProfileFooter.backgroundColor = UIColor.redColor()
                reusable = ProfileFooter
            }

        return reusable
    }

任何人都可以检查其中有什么问题吗??

【问题讨论】:

  • 为什么你同时写了 registerNib 和 registerClass ?删除 registerNib 行。
  • 我已经检查了两者仍然无法正常工作......
  • 像这样写 registerClass 行:registerClass(ProfileFooter, forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "ProfileFooter") 并再次检查页脚视图的标识符是否正确。
  • 我也试过了......不工作

标签: swift uicollectionview uicollectionviewlayout


【解决方案1】:

您在出列时忘记投射页脚视图。 试试这个。

override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
switch kind
 {
  case UICollectionElementKindSectionFooter:
      let profileFooter = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionFooter, withReuseIdentifier: "ProfileFooter", forIndexPath: indexPath) as! ProfileFooter
      profileFooter.backgroundColor = UIColor.redColor()
      return profileFooter
  case default:
      assert(false, "Unexpected element kind")
 }
}

【讨论】:

  • 我在 collectionview 中使用自定义布局
  • 您能否更明确地说明您的代码中的哪些问题。我认识到页脚没有被投射。如果您能提供更多详细信息,那将很有帮助!
猜你喜欢
  • 1970-01-01
  • 2013-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多