在之前的项目中自己写了一个可以折叠展开的UITableView. 思路如下:
1. 使用一个字典保存Table中每个Section打开&折叠的状态, 然后在下面的方法中, 字典返回1则展开cell, 反之折叠cell
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section{//根据表头,到总数组中,筛选出临时数组,确定数量
[[self classArr] objectAtIndex:section];
int rowCount = 0;
for (int i = 0; i < [[self dataArr] count]; i ++) {
CellModel *model = [[self dataArr] objectAtIndex:i];
if (model == [[self classArr] objectAtIndex:section]) {
rowCount ++;
}
}
NSString *key = [NSString stringWithFormat:@"%d", (int)section];
BOOL folded = [[[self switchDict] objectForKey:key] boolValue];
return folded?rowCount:0;
}