Collection 使用 Swift 在 iOS 中使用标题在顶部和右侧的视图

Collection view with Headings on Top and Right in iOS, using Swift

我是 Swift 的新手,遇到了实现 collection 标题在左上角的视图的要求。

HeadersJan,Feb,Mar和Week1,Week2,Week3固定在左上角

对应于 headers 的数据是动态的,我从 JSON 文件中获取,如屏幕截图

不确定从哪里开始实现这种 collection 视图。浏览了很多笔记,但只能找到顶部带有 headers 的视图,但顶部和左侧都找不到。任何代码或参考资料都可能真正有用

根据以下 LINK: http://www.brightec.co.uk/ideas/uicollectionview-using-horizontal-and-vertical-scrolling-sticky-rows-and-columns 当我签入 link 代码时..我在方法 中遇到以下错误 "Type Any has no subscript members"-- itemAttributes 的类型为 NSMutableArray ...我尝试用守卫来保护但失败了。

override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes! {
        return self.itemAttributes[indexPath.section][indexPath.row] as? UICollectionViewLayoutAttributes
    }

。有什么想法吗?

我认为您可以通过将 collectionview 本身作为 collectionview 单元来实现这一点。如果您想以这种方式实现它,那么如果需要,我也可以给出逻辑。