{"id":20620789,"url":"https://github.com/irons163/ircollectiontableviewmodel","last_synced_at":"2025-10-28T09:06:21.001Z","repository":{"id":56915148,"uuid":"200758339","full_name":"irons163/IRCollectionTableViewModel","owner":"irons163","description":"IRCollectionTableViewModel is a powerful MVVM Tableview/CollectionView for iOS, which is flexible and can easy to handle and reuse.","archived":false,"fork":false,"pushed_at":"2020-01-30T06:19:59.000Z","size":799,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-18T19:19:27.487Z","etag":null,"topics":["collectionview","flexible","ios","mvvm","mvvm-architecture","mvvm-pattern","objcective-c","tableview","tableview-collectionview"],"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/irons163.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":"2019-08-06T02:03:32.000Z","updated_at":"2020-01-30T06:20:00.000Z","dependencies_parsed_at":"2022-08-20T21:20:18.330Z","dependency_job_id":null,"html_url":"https://github.com/irons163/IRCollectionTableViewModel","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irons163%2FIRCollectionTableViewModel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irons163%2FIRCollectionTableViewModel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irons163%2FIRCollectionTableViewModel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irons163%2FIRCollectionTableViewModel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/irons163","download_url":"https://codeload.github.com/irons163/IRCollectionTableViewModel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242298971,"owners_count":20104922,"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":["collectionview","flexible","ios","mvvm","mvvm-architecture","mvvm-pattern","objcective-c","tableview","tableview-collectionview"],"created_at":"2024-11-16T12:15:42.378Z","updated_at":"2025-10-28T09:06:15.939Z","avatar_url":"https://github.com/irons163.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Build Status](https://img.shields.io/badge/build-%20passing%20-brightgreen.svg)\n![Platform](https://img.shields.io/badge/Platform-%20iOS%20-blue.svg)\n\n# IRCollectionTableViewModel \n\n- IRCollectionTableViewModel is a powerful MVVM Tableview/CollectionView for iOS, which is flexible and can easy to handle and reuse.\n\n## Features\n- MVVM structure.\n- Flexible, Reusable.\n\n## Install\n### Git\n- Git clone this project.\n- Copy this project into your own project.\n- Add the .xcodeproj into you  project and link it as embed framework.\n#### Options\n- You can remove the `demo` and `ScreenShots` folder.\n\n### Cocoapods\n- Add `pod 'IRCollectionTableViewModel'`  in the `Podfile`\n- `pod install`\n\n## Introduction MVVM\n\n- Model--view--viewmodel (MVVM) is a software architectural pattern.\n- It has advantages more than the tranditional MVC architectural. Can improve the whole code strurcture.\n- More detail can see the MVVM wikipedia. [MVVM](https://en.wikipedia.org/wiki/Model–view–viewmodel)\n\n## Usage\n\n### Basic\n\n#### TableView\n\n- Create a new class `TableViewViewModel` extends `TableViewBasicViewModel\u003cUITableViewDataSource\u003e`, and Import `IRCollectionTableViewModel`\n```obj-c\n#import \u003cIRCollectionTableViewModel/IRCollectionTableViewModel.h\u003e\n\n@interface TableViewViewModel : TableViewBasicViewModel\u003cUITableViewDataSource\u003e\n\n@end\n```\n\n- You can add your init method and register the cell inside\n\n```objc\n- (instancetype)initWithTableView:(UITableView*)tableView;\n\n...\n\n- (instancetype)initWithTableView:(UITableView *)tableView {\n    if (self = [super init]) {\n        items = [[NSMutableArray\u003cid\u003cSectionModelItem\u003e\u003e alloc] init];\n        \n        [tableView registerNib:[UINib nibWithNibName:CELL_NIB_NAME bundle:nil] forCellReuseIdentifier:CELL_IDENTIFIER];\n    }\n    return self;\n}\n```\n\n- Add  `update` method\n```objc\n- (void)update;\n\n...\n\n- (void)update {\n    [items removeAllObjects];\n    // Setup items\n    // [self setupRows];\n}\n\n```\n\n- For setup `items`, other words, setup the sections/rows you want to show. Create `TableViewSectionItem`  and `TableViewRowItem`, `DemoSectionType`, `DemoRowType`\n```objc\ntypedef NS_ENUM(NSInteger, DemoSectionType){\n    DemoSection\n};\n\ntypedef NS_ENUM(NSInteger, DemoRowType){\n    RowType_DemoRow\n};\n\n@interface TableViewRowItem : RowBasicModelItem\n@property (readonly) DemoRowType type;\n@end\n\n@interface TableViewSectionItem : SectionBasicModelItem\n@property (nonatomic) NSString* sectionTitle;\n@property (nonatomic) SectionType type;\n@end\n```\n\n- Implementation `TableViewSectionItem`  and `TableViewRowItem` in the `TableViewViewModel.m`\n```objc\n@implementation TableViewRowItem\n@dynamic type;\n@end\n\n@implementation TableViewSectionItem\n@end\n```\n\n- Setup `items`\n```obj-c\n- (void)setupRows {\n    NSMutableArray *rowItems = [NSMutableArray array];\n    [rowItems addObject:[[TableViewRowItem alloc] initWithType:RowType_DemoRow withTitle:@\"Demo Row\"]];\n    [rowItems addObject:[[TableViewRowItem alloc] initWithType:RowType_DemoRow withTitle:@\"Demo Row\"]];\n    \n    NSArray *demoRowItems = [NSArray arrayWithArray:rowItems];\n    TableViewSectionItem *item = [[TableViewSectionItem alloc] initWithRowCount:[demoRowItems count]];\n    item.type = DemoSection;\n    item.sectionTitle = @\"Demo Section\";\n    item.rows = demoRowItems;\n    [items addObject:item];\n}\n```\n\n- Override `UITableViewDataSource`\n```obj-c\n#pragma mark - UITableViewDataSource\n- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {\n    return items.count;\n}\n\n- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {\n    return [items[section] rowCount];\n}\n\n- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {\n    id\u003cSectionModelItem\u003e item = [items objectAtIndex:indexPath.section];\n    TableViewRowItem *row = (TableViewRowItem *)[item.rows objectAtIndex:[indexPath row]];\n    \n    switch (item.type) {\n        case DemoSection:\n        {\n            switch (row.type) {\n                case RowType_DemoRow:\n                {\n                    TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:TableViewCell.identifier forIndexPath:indexPath];\n                    cell.titleLabel.text = [NSString stringWithFormat:@\"%@%ld\", row.title, row.tagRange.location];\n                    cell.editTextField.text = [editedTexts objectAtIndex:indexPath.row];\n                    cell.editTextField.tag = row.tagRange.location;\n                    cell.editTextField.delegate = self;\n                    return cell;\n                }\n            }\n            break;\n        }\n        default:\n            break;\n    }\n    return [[UITableViewCell alloc] init];\n}\n```\n\n- Use your view model `TableViewViewModel`\n```objc\n#import \"TableViewViewModel.h\"\n\n@implementation TableViewController {\n    TableViewViewModel *viewModel;\n}\n\n- (void)viewDidLoad {\n    [super viewDidLoad];\n    \n    [self.tableView registerNib:[UINib nibWithNibName:HEADER_VIEW_NIB_NAME bundle:nil] forHeaderFooterViewReuseIdentifier:HEADER_VIEW_IDENTIFIER];\n    viewModel = [[TableViewViewModel alloc] initWithTableView:_tableView];\n    _tableView.dataSource = viewModel;\n    [viewModel update];\n}\n\n@end\n```\n\n#### CollectionView\n\n- Just the same way of `TableViewViewModel`. Create a new class `CustomCollectionViewModel` extends `TableViewBasicViewModel\u003cUICollectionViewDataSource\u003e`, and Import this `CustomCollectionViewModel` to view controller\n\n- You can add your init method and register the cell inside\n\n- For setup `items`, other words, setup the sections/rows you want to show. Create `CustomCollectionSectionItem`  and `CustomCollectionRowItem`, `CustomCollectionSectionType`\n\n- Override `UICollectionViewDataSource` \n\n\n### Advanced settings\n\n#### Methos of TableViewBasicViewModel\n\n- `TableViewBasicViewModel` provides some usage methods\n\n```objc\n- (NSInteger)getRowTypeWith:(SectionType)type row:(NSInteger)row;\n- (NSString *)getSectionTitleinSection:(NSInteger)section;\n- (UIImage *)getSectionLeftIconinSection:(NSInteger)section;\n- (SectionType)getSectionTypeinSection:(NSInteger)section;\n- (void)hideRows:(BOOL)hide inSection:(NSInteger)section;\n- (BOOL)hiddenRowsinSection:(NSInteger)section;\n- (NSIndexSet *)getIndexSetWithSectionType:(SectionType)sectionType;\n- (NSIndexPath *)getIndexPathWithSectionType:(SectionType)sectionType rowType:(RowType)rowType;\n- (void)setupRowTag;\n- (NSIndexPath *)getIndexPathFromRowTag:(NSInteger)rowTag;\n```\n#### Tag\n\n- Because the cells have reuse feature, somtimes we need to tag the cell/componenst if want to recognize the specific cell/components, thus  `IRCollectionTableViewModel` provides a tag feature\n\n- Setup tags by `setupRowTag`, it save the tag information in the `tagRange` which is in the `RowBasicModelItem`\n```objc\n- (void)setupRows {\n    ...\n    \n    [self setupRowTag];\n}\n```\n\n- Get tag\n```objc\nTableViewRowItem *row = (TableViewRowItem *)[item.rows objectAtIndex:[indexPath row]];\ntag = row.tagRange.location;\n```\n\n- Get indexPath by tag\n```objc\n- (NSIndexPath *)getIndexPathFromRowTag:(NSInteger)rowTag;\n```\n\n- Sometimes you want to tag the UI components like `UITextField`, use `setTagRangeLength`\n```objc\nTableViewRowItem *row = [[TableViewRowItem alloc] initWithType:RowType_DemoRow withTitle:@\"Demo Row\"];\n[row setTagRangeLength:2];\n\n...\n\n[self setupRowTag];\n```\n\n- Then get tags\n```objc\nTableViewRowItem *row = (TableViewRowItem *)[item.rows objectAtIndex:[indexPath row]];\ntag1 = row.tagRange.location;\ntag2 = row.tagRange.location + 1;\n\ncell.textField1.tag = tag1;\ncell.textField2.tag = tag2;\n```\n\n- The tags are mapping to the same index path\n```objc\n[self getIndexPathFromRowTag:tag1] == [self getIndexPathFromRowTag:tag2]\n```\n\nNow, you can easy to tag anyhing you want.\n\n\n#### Get Row Type\n\n- Hide rows for specific setion by `(void)hideRows:(BOOL)hide inSection:(NSInteger)section`\n\n```objc\n- (NSInteger)getRowTypeWith:(SectionType)type row:(NSInteger)row;\n```\n\n#### Get Section Title\n\n- Get section title which set in the `SectionBasicModelItem`\n\n```objc\n- (NSString *)getSectionTitleinSection:(NSInteger)section;\n```\n\n#### Get Section Left Icon\n\n- Get section icon which set in the `SectionBasicModelItem`\n\n```objc\n- (UIImage *)getSectionLeftIconinSection:(NSInteger)section;\n```\n\n#### Get Section Type\n\n- Get section type by section index\n\n```objc\n- (SectionType)getSectionTypeinSection:(NSInteger)section;\n```\n\n#### Hide Rows\n\n- Hide rows for specific setion by `(void)hideRows:(BOOL)hide inSection:(NSInteger)section`\n- Check hidden status by `(BOOL)hiddenRowsinSection:(NSInteger)section`\n\n```objc\n- (void)hideRows:(BOOL)hide inSection:(NSInteger)section;\n- (BOOL)hiddenRowsinSection:(NSInteger)section;\n```\n\n#### Get Index Set\n\n- Get index of section by section type\n\n```objc\n- (NSIndexSet *)getIndexSetWithSectionType:(SectionType)sectionType;\n```\n\n#### Get IndexPath\n\n- Get index path by section type and row type\n\n```objc\n- (NSIndexPath *)getIndexPathWithSectionType:(SectionType)sectionType rowType:(RowType)rowType;\n```\n\n\n\n## Screenshots\n| TableView | CollectionView |\n|:---:|:---:|\n|![TableView](./ScreenShots/demo1.png)|![CollectionView](./ScreenShots/demo2.png)| \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Firons163%2Fircollectiontableviewmodel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Firons163%2Fircollectiontableviewmodel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Firons163%2Fircollectiontableviewmodel/lists"}