首先定义一个标识符数组,用来表示每个section的展开收起状态
设置每个section的row个数的方法中,加入一个对标识符的判断
判断为 展开,即按照设定的个数来显示row(每个section的row个数,可以存在一个数组里)
判断为收起,则返回0
在header上添加button,绑定方法
方法中,根据button的tag值来判断点击的是哪个section,然后对响应section的标识符进行更改
基本流程就这样了
我写的练习代码供参考(没粘贴变量的声明部分,新手,见笑了...):
#pragma mark - Other Method
//点击header的方法
-(void)tapHeader:(UIButton *)sender
{
if ([[openedInSectionArr objectAtIndex:sender.tag - 100] intValue] == 0) {
[openedInSectionArr replaceObjectAtIndex:sender.tag - 100 withObject:@"1"];
NSLog(@"%d打开",sender.tag);
}
else
{
[openedInSectionArr replaceObjectAtIndex:sender.tag - 100 withObject:@"0"];
设置每个section的row个数的方法中,加入一个对标识符的判断
判断为 展开,即按照设定的个数来显示row(每个section的row个数,可以存在一个数组里)
判断为收起,则返回0
在header上添加button,绑定方法
方法中,根据button的tag值来判断点击的是哪个section,然后对响应section的标识符进行更改
基本流程就这样了
我写的练习代码供参考(没粘贴变量的声明部分,新手,见笑了...):
#pragma mark - Other Method
//点击header的方法
-(void)tapHeader:(UIButton *)sender
{
if ([[openedInSectionArr objectAtIndex:sender.tag - 100] intValue] == 0) {
[openedInSectionArr replaceObjectAtIndex:sender.tag - 100 withObject:@"1"];
NSLog(@"%d打开",sender.tag);
}
else
{
[openedInSectionArr replaceObjectAtIndex:sender.tag - 100 withObject:@"0"];