ZHTableViewGroup为 UITableView 而生
pod 'ZHTableViewGroupObjc'
-
初始化 ZHTableViewDataSource
@property (nonatomic, strong) ZHTableViewDataSource *dataSource;
self.dataSource = [[ZHTableViewDataSource alloc] initWithTableView:self.tableView];
-
[self.dataSource addGroupWithCompletionHandle:^(ZHTableViewGroup *group) {
}
-
[group addCellWithCompletionHandle:^(ZHTableViewCell *cell) {
}
-
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];
}];
-
- (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];
}
[self.dataSource clearData];