ell"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.data = self.scoreDataArray[selectedIndex.row];
cell.isOpen = YES;
return cell;
}
else
{//收起
YunGangScoreTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YunGangScoreTableViewCell"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.data = self.scoreDataArray[selectedIndex.row];
cell.isOpen = NO;
return cell;
}
}
else//不是自身
{
YunGangScoreTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YunGangScoreTableViewCell"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.data = self.scoreDataArray[indexPath.row];
cell.isOpen = NO;
return cell;
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//将索引加到数组中
NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
//判断选中不同row状态时候
//我自己加上的,看好多文章没有,可能我错了,selectedIndex = indexPath;
NSLog(@"%ld",(long)selectedIndex.row);
if (selectedIndex != nil && indexPath.row == selectedIndex.row)
{//将选中的和所有索引都加进数组中
// indexPaths = [NSArray arrayWithObjects:indexPath,selectedIndex, nil];
isOpen = !isOpen;
}
else if (selectedIndex != nil && indexPath.row != selectedIndex.row)
{
indexPaths = [NSArray arrayWithObjects:indexPath, selectedIndex,nil];
isOpen = YES;
}
//记下选中的索引
selectedIndex = indexPath;
//刷新
[tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
}
大致运用的就这些内容,自己看着调试下。。。
方法二: 我试了上面方法,发现可能出现刷新等问题,也就换了下面的
这里用section当做第一个cell,然后加载view到section上,添加手势来作为点击事件,展开的内容加载cell(第二个)
直接上代码:
1.声明属性:
//cell收放,以及记录cell的selectedIndex
NSMutableDictionary *_showDic;//用来判断分组展开与收缩的
int index;
2.用section的个数来展示未点击时的tableview内容
3计算点击每个section之后展开的cell的个数
4.这里自己根据需求,以及返回的内容来计算点开后的cell应该拥有的高度
5.加载点击之后的cell内容,同时传递点击的那个section的数据信息
这里刷新数据是只刷新点开一个情况,如果点开多个,数据改变应该是下面,而在cell里面赋值则不需要了
6.根据需要计算每一个section需要的高度(我这里最后一个有需要)
7.加载每个section的内容,需要注意,这里加载的view继承
UITableViewHeaderFooterView
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
NSArray* objs = [[NSBundle mainBundle] loadNibNamed:@"YunGangScoreTableViewCell" ow