贴出核心代码 主要讲一下思路。
- (void)nameBtnClick:(myButton *)sender {
//获取当前点击的分组对应的section
self.clickIndex = sender.tag - 1000;
HeightModel *model = loadDataArray[self.clickIndex];
if (model.isopen) {
model.isopen = NO;
}
else{
model.isopen = YES;
}
[self.myDeviceListTableview reloadData];
}
我们将tableview 的Style设置成group,在每个分组的header 我们添加一个按钮。按钮点击事件实现方法上面已经贴出来。
mvc模式下,我们使用model 存储后的的数据。类似与qq好友分组和关闭的功能能,在创建model的时候多天假一个BOOL类型的属性。
当点击header 上的button的时候,我们将 存在数组中的 Model取出,将其bool 属性取反。加载数据的时候实现代理方法:代码如下
- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSMutableArray *temparr = meizuArray[section];
NSInteger tempNum;
HeightModel *hmodel = loadDataArray[section];
if (hmodel.isopen) {
tempNum = temparr.count;
}
else{
tempNum = 0;
}
return tempNum;
}
从而实现类似于qq好友列表的打开关闭功能
----- > 有更好的实现方法或者有什么疑问
----- > 请联系QQ: 359276859