Simulator Screen Shot 2017年5月22日 下午1.43.37.png相信大家对于TableViewd数据的设置都熟习,这方面就不多说的,重点的还是来看:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self.tableView deselectRowAtIndexPath:indexPath animated:NO]; currentRow = indexPath.row; NSDictionary *sectionDic = self.dataSource[indexPath.section]; NSArray *cellArray = sectionDic[@"sub"]; //cell当前的数据 NSDictionary *cellData = cellArray[indexPath.row]; NSString *key = [NSString stringWithFormat:@"%@", cellData[@"chapterID"]]; CellModel *chapterModel = [self.cellOpen valueForKey:key]; chapterModel.isShow = !chapterModel.isShow; [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];}当使用户点击到某一个cell时候,需要判断cell能否是开展状态,假如张开或者者收起就调使用
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];让cell的section能够重新加载刷新;
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary *sectionDic = self.dataSource[indexPath.section]; NSArray *cellArray = sectionDic[@"sub"]; //cell当前的数据 NSDictionary *cellData = cellArray[indexPath.row]; NSString *key = [NSString stringWithFormat:@"%@", cellData[@"chapterID"]]; CellModel *model = [self.cellOpen valueForKey:key]; if (model.isShow) { return (model.pois.count+1)*60; } else { return 60; } }-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ BOOL sectionStates = [self.sectionOpen[section] boolValue]; if(sectionStates) { //数据决定显示多少行cell NSDictionary *sectionDict = self.dataSource[section]; //section决定cell的数据 NSArray *cellArray = sectionDict[@"sub"]; return cellArray.count; } else { //section是收起的时候 return 0; }}