CI codecov.io CocoaPod platform CocoaPod version Swift Package Manager compatible Packagist

DTCollectionViewManager

特性

阅读更多 关于最新的 11.0 版本以及与 SwiftUI 的集成!

要求

如果您需要 Xcode 11 支持或 Swift 4...Swift 5.2,或者 iOS 8...iOS 10 支持,您可以使用 7.x 版本。

安装

Swift Package Manager

将 package 添加到 Xcode 项目设置 -> Swift Packages

CocoaPods:

pod 'DTCollectionViewManager', '~> 11.0.0-beta.1'

快速开始

假设您有一个 Posts 数组想要在 UICollectionView 中显示。要使用 DTCollectionViewManager 快速显示它们,您需要这样做

  1. 创建 UICollectionViewCell 子类,比如 PostCell 并采用 ModelTransfer 协议
class PostCell : UICollectionViewCell, ModelTransfer {
    func update(with model: Post) {
        // Fill your cell with actual data
    }
}
  1. 在您的视图控制器中
class PostsViewController: UICollectionViewController, DTCollectionViewManageable {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Register PostCell to be used with this controller's collection view
        manager.register(PostCell.self)

        // Populate datasource
        manager.memoryStorage.setItems(posts)
    }
}    

确保您的 UICollectionView outlet 已连接到您的类(或使用 UICollectionViewController 子类)。如果您有一个 PostCell.xib 文件,它将自动用于出列 PostCell。

  1. 就是这样!就这么简单!

当然,酷炫的东西不止于此,框架支持所有数据源和代理方法作为闭包,条件映射以及更多!在 readme 的下一节中选择您感兴趣的内容。

热门问题

入门包
高级

示例代码和文档

感谢