ZHTableViewGroupObjc 2.5.0

ZHTableViewGroupObjc 2.5.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Apr 2017

Maintained by joser.


Downloads

Total63
Week1
Month44

Installs

Apps7
Apps WeekApps This Week 1
Test Targets4
powered by Segment

GitHub

Stars6
Watchers4
Forks5
Issues0
Contributors0
Pull Requests0

Code

Files12
LOCLines of Code 459


  • By
  • 15038777234

Swift 版本请移步这里

ZHTableViewGroup为 UITableView 而生

怎么安装

pod 'ZHTableViewGroupObjc'

怎么使用

  1. 初始化 ZHTableViewDataSource

    @property (nonatomic, strong) ZHTableViewDataSource *dataSource;
    self.dataSource = [[ZHTableViewDataSource alloc] initWithTableView:self.tableView];
  2. 初始化 ZHTableViewGroup

    [self.dataSource addGroupWithCompletionHandle:^(ZHTableViewGroup *group) {
    }
  3. 初始化 ZHTableViewCell

    [group addCellWithCompletionHandle:^(ZHTableViewCell *cell) {  
    }
  4. 配置 ZHTableViewCell

      cell.anyClass = [UITableViewCell class];
                cell.cellNumber = self.cellTexts.count;
                cell.height = 44;
                cell.identifier = @"UITableViewCellIdentifier";
                [cell setConfigCompletionHandle:^(UITableViewCell *cell, NSIndexPath *indexPath) {
                    NSString *string = self.cellTexts[indexPath.row];
                    cell.textLabel.text = string;
                    if ([self.selectTitles containsObject:string]) {
                        cell.accessoryType = UITableViewCellAccessoryCheckmark;
                    } else {
                        cell.accessoryType = UITableViewCellAccessoryNone;
                    }
                }];
                [cell setDidSelectRowCompletionHandle:^(UITableViewCell *cell, NSIndexPath *indexPath) {
                    NSString *string = self.cellTexts[indexPath.row];
                    if ([self.selectTitles containsObject:string]) {
                        [self.selectTitles removeObject:string];
                    } else {
                        [self.selectTitles addObject:string];
                    }
                    [self.tableView reloadData];
                }];
    
  5. 配置 UITableView的代理

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        return [ZHTableViewDataSource heightForRowAtDataSource:self.dataSource indexPath:indexPath customHeightCompletionHandle:nil];
    }
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return [ZHTableViewDataSource numberOfRowsInSectionWithDataSource:self.dataSource section:section];
    }
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        return [ZHTableViewDataSource cellForRowAtWithDataSource:self.dataSource indexPath:indexPath];
    }
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        [ZHTableViewDataSource didSelectRowAtWithDataSource:self.dataSource indexPath:indexPath];
    }
    

6 清除配置

[self.dataSource clearData];