{"id":18131520,"url":"https://github.com/josercc/swifttableviewgroup","last_synced_at":"2025-04-15T23:04:01.012Z","repository":{"id":56930573,"uuid":"85139999","full_name":"josercc/SwiftTableViewGroup","owner":"josercc","description":"SwiftTableViewGroup 是符合 SwiftUI 设计的 UITableView 和 UICollectionView 数据驱动（SwiftTableViewGroup is a UITableView and UICollectionView data driver compliant with SwiftUI design）","archived":false,"fork":false,"pushed_at":"2019-11-06T02:03:08.000Z","size":5063,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T02:21:50.580Z","etag":null,"topics":["swift5","swiftui","uitableview","uitableviewdatasource","uitableviewdelegate","xcode11"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/josercc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-16T01:49:03.000Z","updated_at":"2020-03-28T18:43:20.000Z","dependencies_parsed_at":"2022-08-21T05:50:19.314Z","dependency_job_id":null,"html_url":"https://github.com/josercc/SwiftTableViewGroup","commit_stats":null,"previous_names":["josercc/zhtableviewgroupswift"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josercc%2FSwiftTableViewGroup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josercc%2FSwiftTableViewGroup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josercc%2FSwiftTableViewGroup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josercc%2FSwiftTableViewGroup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/josercc","download_url":"https://codeload.github.com/josercc/SwiftTableViewGroup/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246363608,"owners_count":20765320,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["swift5","swiftui","uitableview","uitableviewdatasource","uitableviewdelegate","xcode11"],"created_at":"2024-11-01T12:07:49.625Z","updated_at":"2025-03-30T18:31:18.952Z","avatar_url":"https://github.com/josercc.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\ntypora-copy-images-to: ../SwiftTableViewGroup/images/\ntypora-root-url: ../SwiftTableViewGroup\n---\n\n# SwiftTableViewGroup\n\n\u003e ❇️`SwiftTableViewGroup`is developed using the syntax of the latest Swift5.1``@_functionBuilder` combined with the latest `SwiftUI` design pattern.\n\u003e\n\u003e ❇️`SwiftTableViewGroup`是利用最新的`Swift.1`语法`@_functionBuilder`符合`SwiftUI`设计的数据驱动。\n\n[TOC]\n\n## 代码例子\n\n![Snipaste_2019-07-29_14-11-01](/images/Snipaste_2019-07-29_14-11-01-4381583.png)\n\n![Snipaste_2019-07-29_14-13-30](/images/Snipaste_2019-07-29_14-13-30.png)\n\n![Snipaste_2019-07-29_14-18-03](/images/Snipaste_2019-07-29_14-18-03.png)\n\n\n\n![Snipaste_2019-07-29_14-19-23](/images/Snipaste_2019-07-29_14-19-23.png)\n\n## ChangeLog(更新记录)\n\n### v2.0.0\n\n- Support `UICollectionView` data driver(支持`UICollectionView`数据驱动)\n- Changing `Api` is easier to use(更改`Api`使用更简单)\n- Support for custom height or size(支持自定义高度或者大小)\n- Safer to use(使用更加安全)\n\n## 安装\n\n### Swift Package Manager(Xcode 11)\n\n```ruby\nhttps://github.com/josercc/SwiftTableViewGroup\n```\n\n### CocoaPods\n\n```swift\npod 'SwiftTableViewGroup'\n```\n\n### Carthage\n\n```ruby\ngithub \"josercc/SwiftTableViewGroup\"\n```\n\n## Claim(要求)\n\n- `Xcode11`\n- `Swift5.1`\n\n## How to use(怎么使用)\n\n### UITableView\n\n#### Fake code(伪代码)\n\n```swift\nlet tableView = UITableView()\nvar dataSource = TableView(tableView:tableView)\n/// setup configuration(初始化配置)\ndataSource.setup {\n  /// Add Header\n  TableViewHeaderFooterView\n  /// Add Cell\n  TableViewCell\n  /// Add More Cell\n  ...\n  /// Add Footer\n  TableViewHeaderFooterView\n}\n/// Perform registration and refresh(执行注册和刷新)\ndataSource.reloadData\n```\n\n#### Create a static text list(创建一个简单的列表)\n\n```swift\nTableCell { content, contentCell in\n    /// Create a configured block(创建配置的 Block)\n    content.configuration(UITableViewCell.self) { (cell, index) in\n        cell.textLabel?.text = self.source[index]\n        cell.accessoryType = .disclosureIndicator\n    }\n    /// Create a clickback call block(创建点击回调 Block)\n    content.didSelectRow(UITableViewCell.self) { (cell, index) in\n    }\n}\n.number(self.source.count)\n.height(45)\n}\nself.dataSource.reloadData()\n```\n\n![image-20190726143607274](/images/2019-07-26-063607.png)\n\n#### Create complex TableView(创建复杂的表格)\n\n```swift\nlet settingDataSource = TableView(tableView: tableView)\nsettingDataSource.setup {\n  \t/// Create `SettingHeaderView` Header(创建自定义`SettingHeaderView`Header)\n    TableHeaderView(SettingHeaderView.self, { content,contentHeader in\n        content.configuration(SettingHeaderView.self) { (view, section) in\n            view.textLabel?.text = \"Header\"\n        }\n    })\n    .height(49)\n\t\t/// Create `IntrinsicContentTextLabelCell` Cell(创建`IntrinsicContentTextLabelCell`Cell)\n    TableCell(IntrinsicContentTextLabelCell.self)\n  \t/// Create Dynamic change number Cell(创建动态更改数量的 Cell)\n    TableCell { content,contentCell in\n        content.configuration(UITableViewCell.self) { (cell, index) in\n            cell.textLabel?.text = \"\\(index) 点击我会增加哦\"\n        }\n        content.didSelectRow(UITableViewCell.self) { (cell, index) in\n            let number = contentCell.number + 1;\n            contentCell.number(number)\n            settingDataSource.reloadData()\n        }\n    }\n    .height(44)\n  \t/// Create Dynamic change height Cell）(创建动态更改高度的 Cell)\n    TableCell { content,contentCell in\n        content.configuration(UITableViewCell.self) { (cell, index) in\n            cell.textLabel?.text = \"点击我改变高度\"\n        }\n        content.didSelectRow(UITableViewCell.self) { (cell, index) in\n            let height = contentCell.height == 44 ? 100 : 44;\n            contentCell.height(CGFloat(height))\n            settingDataSource.reloadData()\n        }\n    }\n    .height(44)\n}\n```\n\n![image-20190726143714253](/images/image-20190726143714253.png)\n\n##### Dynamic change quantity(动态更改数量)\n\n![image-20190726145544399](/images/image-20190726145544399.png)\n\n##### Dynamic height(动态修改高度)\n\n![image-20190726145605726](/images/image-20190726145605726.png)\n\n### UICollectionView\n\n```swift\nself.dataSource.setup {\n  \t/// Create normal class `UICollectionViewCell` cell(创建默认为`UITableViewCell`类的 Cell)\n    CollectionCell { content, cellContent in\n        content.configuration(UICollectionViewCell.self) { (cell, index) in\n            cell.backgroundColor = index % 2 == 0 ? UIColor.red : UIColor.blue\n        }\n        content.didSelectRow(UICollectionViewCell.self) { (cell, index) in\n            cell.backgroundColor = cell.backgroundColor == UIColor.red ? UIColor.blue : \t\tUIColor.red\n        }\n    }\n    .number(20)\n    .size(CGSize(width: 100, height: 200))\n\n}\n.inset(UIEdgeInsets(top: 20, left: 10, bottom: 20, right: 10))\nself.dataSource.reloadData()\n```\n\n![image-20190729105419637](/images//image-20190729105419637.png)\n\n## Problem\n\n### ❓How to dynamically insert or delete some elements(怎么动态的插入或者删除一组元素)\n\n\u003e You can change the element properties of the opposite side of the TableView's Sections array and then call `reloadData`.(您可以更改TableView的Sections数组的另一侧的元素属性，然后调用`reloadData`。)\n\n### ❓How to listen to other agents of `UIScrollView`(怎么监听`UIScrollView`其他代理方法)\n\n```swift\npublic struct ScrollViewDelegate {\n    public var scrollViewDidScroll:((_ scrollView: UIScrollView) -\u003e Void)?\n    public var scrollViewWillBeginDragging:((_ scrollView: UIScrollView) -\u003e Void)?\n    public var scrollViewWillEndDragging:((_ scrollView: UIScrollView, _ velocity: CGPoint, _ targetContentOffset: UnsafeMutablePointer\u003cCGPoint\u003e) -\u003e Void)?\n    public var scrollViewDidEndDragging:((_ scrollView: UIScrollView, _ decelerate: Bool) -\u003e Void)?\n    public var scrollViewWillBeginDecelerating:((_ scrollView: UIScrollView) -\u003e Void)?\n    public var  scrollViewDidEndDecelerating:((_ scrollView: UIScrollView) -\u003e Void)?\n}\n\n```\n\n\u003e Can implement the above proxy method of `UITableView`(可以实现`UITableView的上述代理方法)\n\nExample\n\n```swift\ntableView.scrollDelegate?.scrollViewDidScroll = { scrollView in\n}\n```\n\n### I feel that there are too few supported features.(我觉得支持的功能太少了。)\n\n\u003e Can submit PR or commit ISSUSE(可以提交PR或提ISSUSE)\n\n## Api Document(Api 文档)\n\n- Height or size setting priority (高度或者大小的设置优先级)\n  - height( UITableViewCell/UITableHeaderFooterView)(高度( UITableViewCell/UITableHeaderFooterView))\n    - custom \u003e setting \u003e auto(sizeToFit)(自定义 \u003e 设置 \u003e 自动获取(sizeToFit))\n  - size(UICollectionViewCell/UICollectionReusableView)(大小(UICollectionViewCell/UICollectionReusableView))\n    - custom \u003e setting \u003e FlowLayout(自定义 \u003e 设置 \u003e FlowLayout)\n\n## contact me\n\n- Email: josercc@163.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosercc%2Fswifttableviewgroup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjosercc%2Fswifttableviewgroup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosercc%2Fswifttableviewgroup/lists"}