2017-03-27 66 views
1

我想創建一個簡單的自定義佈局UICollectionView以編程方式使用(即沒有界面生成器)。UICollectionView自定義佈局。補充意見不顯示或查詢

我根據文檔做的一切:

  1. 子類UICollectionViewLayout並準備我的佈局
  2. 覆蓋layoutAttributesForSupplementaryView(ofKind elementKind: String, at indexPath: IndexPath)並返回相應的佈局屬性
  3. 添加collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath)實現,我回到我的補充視圖

我的問題是,既沒有collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath)也沒有layoutAttributesForSupplementaryView(ofKind elementKind: String, at indexPath: IndexPath)正在調用,所以我看不到我的補充意見。

我已經仔細檢查了我的實現都佈局和補充視圖創建,但我仍然無法得到它的工作。

回答

3

顯然,這是不夠的,有layoutAttributesForSupplementaryView(ofKind elementKind: String, at indexPath: IndexPath) -> UICollectionViewLayoutAttributes?其返回的補充意見的屬性。

人們還需要返回補充意見的屬性在layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes?

我的錯誤是,我是爲細胞在layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes?

只返回佈局屬性一旦我添加布局屬性的補充意見納入返回的值通過layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes?我有我的數據源方法調用和補充意見返回。

編輯:這個答案涵蓋了iOS10 SDK。我還沒有嘗試過早期版本

+0

可以發佈完整的代碼嗎? –

+0

layoutAttributesForItem()?不是RECT? –

相關問題