参考了SKSTableView的设计思想,工程在github上,我由于没有连接就不贴了git
思路1是用tableView的head做为一级菜单,其余都是每个section的全部cell,这种方法看起来很好数据是数据,标题是标题github
思路二是用TableView的每个section的row 0 作标题,其他的是数据,这种方法更为简单点,可是逻辑处理将会复杂一些spa
思路一通过一番实验后发现,问题主要表如今如何让headView响应点击事件,因而将tableview的headview添加一个button,而后让点击时候设置当前的section的行数为0;进而达到所须要的效果设计
BOOL _open;
NSInteger _lastOpen;代理
_datasouth = [[NSMutableArray alloc] initWithArray:@[@[@"miao", @"miao1",@"miao12"],
@[@"nong", @"nong1", @"nong12", @"Rnong13", @"nong14", @"nong15", @"nong16", @"Rnong17"],
@[@"fei", @"fei1",@"fei1"],
@[@"lei"],
@[@"wu"]]];事件
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return _datasouth.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (_open == 0) {
return 1;
}
if (_lastOpen == section) {
NSArray * arr = _datasouth[section];
return arr.count;
}
return 1;
}it
if (indexPath.row == 0) {io
//组名cell
table
if ([_datasouth[indexPath.section] count] == 1) {
//无分组的cell自定义ast
//等同于底层cell,执行跳转?
}
} else {
//底层cell,执行跳转?
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0 && [_datasouth[indexPath.section] count] == 1) {
//跳转;
return;
}
if (_open == 0) {
if (indexPath.row == 0) {
_open = 1;
_lastOpen = indexPath.section;
}
} else {
if (indexPath.row == 0) {
if (_lastOpen == indexPath.section) {
_open = 0;
_lastOpen = -1;
}
_lastOpen = indexPath.section;
}
}
[_tableView reloadData];
//[_tableView reloadSections:[NSIndexSet indexSetWithIndex:_lastOpen] withRowAnimation:UITableViewRowAnimationAutomatic];
if (indexPath.row != 0) {
//跳转
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) { return 40; }; return 70;}- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return .01;}- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 5)]; return view;}