Dequer 1.2.3

Dequer 1.2.3

Mohamad Reza Koohkan 维护。



Dequer 1.2.3

  • 作者
  • mohamadrezakoohkan

Dequer is Light weight library to handle Any Cell

Dequer

Dequer 是一个轻量级的库,用于处理任意单元格

在 iOS 开发中使用最多的一个是,通过 DataSources 使用 UITableViewCellStyle 进行 deque,它有一些配置。我创建了一个扩展和协议,可以尽可能重用单元格。

可用性

对于在协议中使用的闭包完成处理器块,每个 单元格类 都应该使用 final 标记,这意味着不能重写此类或将其用作父类和阻止继承。

面向协议

所有符合 Dequer单元格类 都可以使用此代码。

额外

Cell 中有一个静态变量 height 用于 UITableViewCellsize 用于 UICollectionViewCell,用于存储单元格的默认高度。这是一个可选的变量,您可以删除它。

需求

  • 支持iOS 9.3+
  • Swift 4.0+

与Swift 5.x 版本完全兼容

安装

CocoaPods

CocoaPods 是 Cocoa 项目的依赖管理器。关于使用和安装说明,请访问他们的网站。要使用 CocoaPods 将 Dequer 集成到您的 Xcode 项目中,请在您的 Podfile 中指定它。

pod 'Dequer', :git => 'https://github.com/mohamadrezakoohkan/Dequer.git'

Swift 包管理器

您可以使用 Swift 包管理器 通过将 Dequer 包描述添加到您的 Package.swift 文件来安装 Dequer

// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    dependencies: [
        .package(url: "https://github.com/mohamadrezakoohkan/Dequer.git", from: "1.2.0"),
    ]
)

然后,在终端中运行 swift build 来构建 Dequer

手动方式

如果您愿意不使用上述任何依赖项管理器,您可以使用源代码手动操作。从 发布 获取最新版。

使用方法

示例项目

将项目克隆并使用示例项目。

如何在项目中实现Deque的示例。

import UIKit
import Dequer

final class PersonCell: UITableViewCell, Dequer {

    static var height: CGFloat = 40

    override func awakeFromNib() {
        super.awakeFromNib()

    }

}
    

在UITableViewDataSource内部

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    return PersonCell.deque(in: tableView, at: indexPath) { (cell, row) in
        cell.textLabel?.text = \(row)
    }
}

数据绑定

由于在 cellForRowAtcellForItemAt 中绑定数据应当避免,我创建了一个名为 bind 的方法,可用于数据绑定。在 这个提交 中使用。

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    return AnimalCell.deque(in: collectionView, at: indexPath)
}

override func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
    AnimalCell.bind(to: cell) {
        $0.animal = self.animals[indexPath.row]
    }
}

联系

InstagramGithubLinkedInStack Overflow 上关注和联系我。如果您发现任何问题,请 提交工单。您可以通过以下邮箱发送邮件:[email protected]

许可

Dequer项目采用 MIT 许可协议 发布。