{"id":32320497,"url":"https://github.com/laizhenwei/rxtableview","last_synced_at":"2025-10-23T11:55:57.488Z","repository":{"id":62452335,"uuid":"103117952","full_name":"laizhenwei/RXTableView","owner":"laizhenwei","description":"RXTableView 是基于 ReactiveCocoa 和 MVVM 的基础上一个响应式 tableView。","archived":false,"fork":false,"pushed_at":"2017-09-11T10:00:34.000Z","size":24,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-23T11:55:56.956Z","etag":null,"topics":["mvvm","objcective-c","reactivecocoa"],"latest_commit_sha":null,"homepage":null,"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/laizhenwei.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-09-11T09:40:33.000Z","updated_at":"2017-12-04T06:24:38.000Z","dependencies_parsed_at":"2022-11-01T23:45:38.913Z","dependency_job_id":null,"html_url":"https://github.com/laizhenwei/RXTableView","commit_stats":null,"previous_names":["laichanwai/rxtableview"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/laizhenwei/RXTableView","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laizhenwei%2FRXTableView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laizhenwei%2FRXTableView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laizhenwei%2FRXTableView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laizhenwei%2FRXTableView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/laizhenwei","download_url":"https://codeload.github.com/laizhenwei/RXTableView/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laizhenwei%2FRXTableView/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280614540,"owners_count":26360842,"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","status":"online","status_checked_at":"2025-10-23T02:00:06.710Z","response_time":142,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["mvvm","objcective-c","reactivecocoa"],"created_at":"2025-10-23T11:55:52.500Z","updated_at":"2025-10-23T11:55:57.482Z","avatar_url":"https://github.com/laizhenwei.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"#  RXTableView\n\nRXTableView 是基于 ReactiveCocoa 和 MVVM 的基础上造的一个 tableView 轮子。\n\n抛弃繁杂重复的 TableView 代理实现和 Cell 管理，加入灵活的数据绑定，`RXTableView` 是一种新的体验。\n\n### WorkFlow\n\n\u003e 在 MVVM 编程中，View 负责显示，Model 负责模型，它们都是相对比较稳定的，一般不会轻易改动代码。\n\u003e ViewModel 主要是负责业务，一般的数据获取、加工和绑定都是在这里完成。\n\n在使用 RXTableView 中，你只需要完成 4 个步骤:\n\n1. 定义 Model，并遵循 `RXCellModel` 协议\n2. 添加自定义 UITableViewCell，并实现 `+ (CGFloat)cellHeightForCellModel:(id\u003cRXCellModel\u003e)cellModel` 方法\n3. 在 ViewModel 中获取数据，并绑定 `cellClass`\n4. 创建 RXTableView，并绑定相关命令和 `ViewModel` 的数据源\n\n#### 定义 Model\n\n自定义 Model 并遵循 `RXCellModel`\n\n`RXCellModel` 的协议方法已经在分类中实现，自定义 Model 无需自己实现\n\n```objc\n#import \"NSObject+RX.h\"\n\n@interface FeedModel : NSObject \u003cRXCellModel\u003e\n// ...\n@end\n```\n\n#### 添加自定义 `UITableViewCell`\n\n自定义 `UITableViewCell`，并参照 `RXTableViewCell` 的协议方法，按需实现。\n\n`RXTableViewCell` 的协议方法已在分类中实现\n\n自定义 Cell 需要实现 `+ (CGFloat)cellHeightForCellModel:(id\u003cRXCellModel\u003e)cellModel` 方法返回 Cell 的高度。\n\n- 自动计算高度\n\n```objc\n+ (CGFloat)cellHeightForCellModel:(id\u003cRXCellModel\u003e)cellModel {\n    return UITableViewAutomaticDimension;\n}\n\n// 自动计算高度需要给 estimatedRowHeight 赋一个近似值\ntableView.estimatedRowHeight = 100;\n```\n\n#### 绑定 `cellClass`\n\n```objc\n// 获取数据\nNSArray *models = [NSArray modelArrayWithClass:[FeedModel class] json:data];\nfor (FeedModel *model in models) {\n    // 绑定 CellModel 和 Cell\n   model.cellClass = NSClassFromString(@\"FeedTableViewCell\");\n    // 预加载高度\n   [model cellHeight];\n}\n\n// 更新数据源\nself.models = models;\n```\n\n#### 创建 TableView\n\n```objc\n// 创建 viewModel\nself.viewModel = [[FeedViewModel alloc] init];\n// 创建 tableView\nRXTableView *tableView = [[RXTableView alloc] initWithFrame:self.view.bounds];\n\n// 绑定下拉刷新命令\ntableView.refreshCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {\n    ...\n}];\n// 绑定上拉加载命令\ntableView.loadMoreCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {\n    ...\n}];\n// 绑定选中 cell 命令\ntableView.didSelectCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(RACTuple *input) {\n    ...\n}];\n\n// 数据源绑定\nRAC(tableView, models) = RACObserve(self.viewModel, models);\n\n// 显示 tableView 并加载数据\n[self.view addSubview:tableView];\n[tableView.mj_header beginRefreshing];\n```\n\n#### 自定义实现数据源和代理方法\n\nRXTableView 对 `dataSource` 和 `delegate` 做了中转处理，会优先使用用户自定义的代理，其次才会使用 `RXtableView` 自身实现的代理方法。\n\n如果你需要自己实现 `UITableViewDataSource` 或者 `UITableViweDelegate`，那么你可以把它当做 `UITableView` 来使用。\n\n```objc\n@implementation ViewController\n// ...\n- (void)registerTableView {\n    tableView.dataSource = self;\n    tableView.delegate = self;\n}\n\n- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {\n    // 点击 Cell 后会忽略 didSelectCommand，进入该方法\n}\n// ...\n@end\n```\n\n### 项目依赖\n\n- [ReactiveObjc](https://github.com/ReactiveCocoa/ReactiveObjC)\n- [MJRefresh](https://github.com/CoderMJLee/MJRefresh)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaizhenwei%2Frxtableview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaizhenwei%2Frxtableview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaizhenwei%2Frxtableview/lists"}