{"id":18725089,"url":"https://github.com/indulgein/ybhandytableview","last_synced_at":"2025-04-12T15:50:51.599Z","repository":{"id":56928836,"uuid":"160947969","full_name":"indulgeIn/YBHandyTableView","owner":"indulgeIn","description":"让复杂 TableView 优雅起来，更轻易的实现动态化","archived":false,"fork":false,"pushed_at":"2019-09-08T01:47:44.000Z","size":176,"stargazers_count":65,"open_issues_count":1,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T04:06:11.645Z","etag":null,"topics":["dynamic","efficiency","tableview"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","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/indulgeIn.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":"2018-12-08T14:39:13.000Z","updated_at":"2024-09-09T06:23:26.000Z","dependencies_parsed_at":"2022-08-20T23:30:27.246Z","dependency_job_id":null,"html_url":"https://github.com/indulgeIn/YBHandyTableView","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indulgeIn%2FYBHandyTableView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indulgeIn%2FYBHandyTableView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indulgeIn%2FYBHandyTableView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indulgeIn%2FYBHandyTableView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/indulgeIn","download_url":"https://codeload.github.com/indulgeIn/YBHandyTableView/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248591905,"owners_count":21130147,"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":["dynamic","efficiency","tableview"],"created_at":"2024-11-07T14:09:02.827Z","updated_at":"2025-04-12T15:50:51.578Z","avatar_url":"https://github.com/indulgeIn.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# YBHandyTableView\n\n[![Cocoapods](https://img.shields.io/cocoapods/v/YBHandyTableView.svg)](https://cocoapods.org/pods/YBHandyTableView)\u0026nbsp;\n[![Cocoapods](https://img.shields.io/cocoapods/p/YBHandyTableView.svg)](https://github.com/indulgeIn/YBHandyTableView)\u0026nbsp;\n[![License](https://img.shields.io/github/license/indulgeIn/YBHandyTableView.svg)](https://github.com/indulgeIn/YBHandyTableView)\u0026nbsp;\n\n让复杂 TableView 优雅起来，更轻易的实现动态化。\n\n原理解析博客：[iOS 架构组件：让复杂 TableView 优雅起来](https://www.jianshu.com/p/7db73489ad99)\n\n**注意：** 新版本独立了一个 repo [YBHandyList](https://github.com/indulgeIn/YBHandyList)，放弃了多代理，支持 UICollectionView。\n\n## 特性\n\n- 模块化思维，使用数组配置 UITableView，优雅解决复杂布局和动态布局\n- 轻量化设计，不会覆盖原生功能\n- IOP 思想，使用或弃用都随心所欲，不拖泥带水\n- 除了不需要实现数据源协议，还不需要注册 Cell/Header/Footer\n\n\n## 安装\n\n### CocoaPods\n\n1. 在 Podfile 中添加 `pod 'YBHandyTableView'`。\n2. 执行 `pod install` 或 `pod update`。\n3. 导入 `\u003cYBHandyTableView/UITableView+YBHandyTableView.h\u003e`。\n\n若搜索不到库，可使用 rm ~/Library/Caches/CocoaPods/search_index.json 移除本地索引然后再执行安装，或者更新一下 CocoaPods 版本。\n\n### 手动导入\n\n1. 下载 YBHandyTableView 文件夹所有内容并且拖入你的工程中。\n2. 导入 `UITableView+YBHandyTableView.h`。\n\n\n## 用法\n\n可下载 DEMO 查看示例。\n\n### 核心思想\n\n对于 UITableView，每一个 Header、Footer、Cell 都对应一个配置对象：\n- Header / Footer : `id\u003cYBHTHeaderFooterConfigProtocol\u003e`\n- Cell : `id\u003cYBHTCellConfigProtocol\u003e`\n\n所以，使用该组件第一步就是构建和视图等量的配置对象。\n\n### 简洁使用\n\n为了简洁，特意设置了一些语法糖，比如默认实现了两个配置对象：\n```\nYBHTCellConfig 实现 \u003cYBHTCellConfigProtocol\u003e\nYBHTHeaderFooterConfig 实现 \u003cYBHTHeaderFooterConfigProtocol\u003e\n```\n由于 UITableView 可能只需要一个 Section，所以使用一些语法糖可以便捷使用：\n```\n// 构造数据模型 (通常来自于网络)\nTCEasyModel *model0 = TCEasyModel.new;\nmodel0.text = @\"第一条数据\";\nTCEasyModel *model1 = TCEasyModel.new;\nmodel1.text = @\"第二条数据\";\n\n// 构造配置数据\nYBHTCellConfig *c0 = [YBHTCellConfig new];\nc0.model = model0;\nc0.cellClass = TCEasyCell.self;\nYBHTCellConfig *c1 = [YBHTCellConfig new];\nc1.model = model1;\nc1.cellClass = TCEasyCell.self;\n\n// 赋值 tableview 并刷新\n[self.tableView.ybht_rowArray addObjectsFromArray:@[c0, c1]];\n[self.tableView reloadData];\n```\n同时，对应的 Cell 需要实现`\u003cYBHTCellConfigProtocol\u003e`协议：\n```\n@interface TCEasyCell () \u003cYBHTCellProtocol\u003e\n@end\n@implementation TCEasyCell\n#pragma mark - \u003cYBHTCellProtocol\u003e\n- (void)ybht_setCellConfig:(id\u003cYBHTCellConfigProtocol\u003e)config {\n    //此处根据配置对象获取相应的数据模型\n    YBHTCellConfig *cellConfig = (YBHTCellConfig *)config;\n    TCEasyModel *model = (TCEasyModel *)cellConfig.model;\n    // 更新 UI\n}\n+ (CGFloat)ybht_heightForCellWithConfig:(id\u003cYBHTCellConfigProtocol\u003e)config reuseIdentifier:(NSString *)reuseIdentifier indexPath:(NSIndexPath *)indexPath {\n    //此处可根据 config 自行计算高度，也可以用 UITableView+FDTemplateLayoutCell 开源库计算 \n    return UITableViewAutomaticDimension;\n}\n@end\n```\n\n### 完整使用\n\n完整的使用方式是使用`tableView.ybht_sectionArray`，它的定义如下，\n```\n@property (nonatomic, strong, readonly) NSMutableArray\u003cYBHTSection *\u003e *ybht_sectionArray;\n```\n`YBHTSection`表示了一个 Section 包含的所有配置对象：\n```\n@interface YBHTSection : NSObject\n/** UITableView 的 header 配置 */\n@property (nonatomic, strong, nullable) id\u003cYBHTHeaderFooterConfigProtocol\u003e headerConfig;\n/** UITableView 的 footer 配置 */\n@property (nonatomic, strong, nullable) id\u003cYBHTHeaderFooterConfigProtocol\u003e footerConfig;\n/** UITableView 的 cell 配置数组 */\n@property (nonatomic, strong, readonly) NSMutableArray\u003cid\u003cYBHTCellConfigProtocol\u003e\u003e *rowArray;\n\n@end\n```\n\n下载 DMEO 可更快速的上手。\n\n\n### Cell / Header / Footer 事件和数据传递\n\n由于 Cell / Header / Footer 被抽象出来了，外界与它们联系的最好方式是通过配置对象 （或其属性），即是`id\u003cYBHTCellConfigProtocol\u003e`/`id\u003cYBHTHeaderFooterConfigProtocol\u003e`。\n\n通过配置对象（或其属性）持有一个代理对象 delegate，然后在 Cell / Header / Footer 里面通过 delegate 达到向外界传递事件和数据的目的。\n\n具体的操作可看 Demo，更多的传递方式可看技术博客。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findulgein%2Fybhandytableview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Findulgein%2Fybhandytableview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findulgein%2Fybhandytableview/lists"}