AlisterSwift 1.0.0

AlisterSwift 1.0.0

Oleksandr VelykotskyiAlex Kravchenko 维护。



  • Oksana Kovalchuk、Alexander Kravchenko、Maxim Danilov、Pavel Mosunov 和 Simon Kostenko 制作

AlisterSwift

Version License Platform

CocoaPods compatible Swift Package Manager Build Status

概览

Alister 允许管理任何 UITableViewUICollectionView 的内容。基本思想是提供一个同步数据与单元格外观的层,以便进行类似添加、移动、删除和重新排列的操作。Alister 自动处理 UITableViewUICollectionView 的数据源和代理协议,您可以通过从基本控制器中子类化来覆盖它们。

特性

  • UITableViewUICollectionView 一起工作
  • 支持对部分和行执行所有操作,如 InsertDeleteMoveReload
  • 支持 UISearchBar 并提供搜索谓词
  • 支持自定义头部和尾部视图
  • 提供键盘处理
  • 作为 ANTableView 的一部分提供底部固定的尾部

使用方法

初始化列表控制器

private let controller: TableController
...
init() {
	controller = TableController(tableView: tableView)
	super.init(nibName: nil, bundle: nil)
}

注册单元格、标题和页脚

controller.configureCells { (config) in
	config.register(cell: CarCell.self, for: CarCellViewModel.self)
	config.register(footer: CarsTableHeaderFooter.self, for: CarsTableHeaderFooterVM.self)
	config.register(header: CarsTableHeaderFooter.self, for: CarsTableHeaderFooterVM.self)
}

将模型添加到存储

controller.storage.update { [unowned self] (update) in

	// Adding rows to the table
	update.add(modelsSection1)
	update.add(modelsSection2, to: 1)

	// Adding header and footer to some sections
	update.update(headerModel: CarsTableHeaderFooterVM(title: "Section 0 Header"), section: 0)
	update.update(headerModel: CarsTableHeaderFooterVM(title: "Section 1 Header"), section: 1)
	update.update(footerModel: CarsTableHeaderFooterVM(title: "Section 1 Footer"), section: 1)
}

添加搜索栏

controller.attachSearchBar(searchBar)

到此完成!

处理选择

选项 1:ViewModel 风格

model.selection = {
	self.showAlert(title: model.alertTitle)
}

选项 2:Controller 风格

tableController.selection = { viewModel, indexPath in
	...
}

示例 项目中查看更多此功能和其它功能的说明

概览

Alister 允许管理任何 UITableViewUICollectionView 的内容。基本思想是提供一个同步数据与单元格外观的层,以便进行类似添加、移动、删除和重新排列的操作。Alister 自动处理 UITableViewUICollectionView 的数据源和代理协议,您可以通过从基本控制器中子类化来覆盖它们。

功能

  • UITableViewUICollectionView 一起工作
  • 支持对部分和行执行所有操作,如 InsertDeleteMoveReload
  • 支持 UISearchBar 并提供搜索谓词
  • 支持自定义头部和尾部视图
  • 提供键盘处理
  • 作为 ANTableView 的一部分提供底部固定的尾部

使用方法

初始化列表控制器

private let controller: TableController
...
init() {
    controller = TableController(tableView: tableView)
    super.init(nibName: nil, bundle: nil)
}

注册单元格、标题和页脚

controller.configureCells { (config) in
    config.register(cell: CarCell.self, for: CarCellViewModel.self)
    config.register(footer: CarsTableHeaderFooter.self, for: CarsTableHeaderFooterVM.self)
    config.register(header: CarsTableHeaderFooter.self, for: CarsTableHeaderFooterVM.self)
}

将模型添加到存储中

controller.storage.update { [unowned self] (update) in

    // Adding rows to the table
    update.add(modelsSection1)
    update.add(modelsSection2, to: 1)

    // Adding header and footer to some sections
    update.update(headerModel: CarsTableHeaderFooterVM(title: "Section 0 Header"), section: 0)
    update.update(headerModel: CarsTableHeaderFooterVM(title: "Section 1 Header"), section: 1)
    update.update(footerModel: CarsTableHeaderFooterVM(title: "Section 1 Footer"), section: 1)
}

添加搜索栏

controller.attachSearchBar(searchBar)

到此完成!

处理选择

选项 1:ViewModel 风格

model.selection = {
    self.showAlert(title: model.alertTitle)
}

选项 2:Controller 风格

tableController.selection = { viewModel, indexPath in
    ...
}

示例 项目中查看更多此功能和其它功能的说明

运行

在本地机器上构建,请首先生成xcodeproj

swift package generate-xcodeproj

示例

要运行示例项目,请先克隆仓库,然后从Example目录运行pod install

需求

Xcode 8+,Swift 4+。

安装

AlisterSwift可以通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中

pod 'AlisterSwift'

作者

Оксана Ковалюк,[email protected]
Александр Кравченко,[email protected]
Максим Данилов,[email protected]
Павел Мосунов,[email protected]
Симон Косенко,[email protected]

许可协议

AlisterSwift可在MIT许可协议下获得。有关更多信息,请参阅LICENSE文件。