<UITableViewDelegate,UITableViewDatasource>
- (void)_creatTableView{
_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 100, SCREEN_WIDTH, SCREEN_HEIGHT - 100) style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.backgroundColor = [UIColor yellowColor];
[_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIdentify];
[self.view addSubview:_tableView];
}
#pragma mark UITableViewDelegate
//組數(shù)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 6;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *headView = [[UIView alloc]init];
headView.backgroundColor = [UIColor whiteColor];
UILabel *headTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, 20, 20)];
headTitle.text = [NSString stringWithFormat:@"%ld",section];
[headView addSubview:headTitle];
//下拉按鈕的設(shè)置
UIButton* pullDownbtn =[UIButton buttonWithType:UIButtonTypeCustom];
pullDownbtn.frame = CGRectMake(SCREEN_WIDTH - 100, 0, 20, 20);
//[pullDownbtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
pullDownbtn.tag = section;
[pullDownbtn addTarget:self action:@selector(pullDownAction:) forControlEvents:UIControlEventTouchUpInside];
[headView addSubview:pullDownbtn];
//下拉按鈕圖標(biāo)
UIImageView *pullDownbtnView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, pullDownbtn.size.width, pullDownbtn.size.height)];
//? ? pullDownbtnView.image = [UIImage imageNamed:@"CHANGJIN_icon_all@2x.png"];
pullDownbtnView.backgroundColor = [UIColor redColor];
[pullDownbtn addSubview:pullDownbtnView];
return headView;
}
#pragma mark 組頭視圖上的按鈕點(diǎn)擊事件
- (void)pullDownAction:(UIButton *)sender{
NSInteger section = sender.tag;
//改變數(shù)組中元素的狀態(tài)
flag[section] = !flag[section];
NSIndexSet *set = [NSIndexSet indexSetWithIndex:section];
[_tableView reloadSections:set withRowAnimation:UITableViewRowAnimationFade];
[_tableView reloadData];
}
#pragma mark 設(shè)置不同的組有不同的行數(shù)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//? ? BOOL f = flag[section]; //NO :展開(kāi)
//? ? if(!f){
//? ? ? ? return 0;? //場(chǎng)景列表不展開(kāi)
//? ? }else{
//? ? ? ? for (NSInteger i = 0; i < [titleArray count]; i++) {
//? ? ? ? ? ? if (section == i) {
//? ? ? ? ? ? ? ? return [[dataArray objectAtIndex:section]count];
//? ? ? ? ? ? }
//? ? ? ? }
//? ? ? ? return [[dataArray objectAtIndex:section]count];
//? ? }
BOOL f = flag[section]; //NO :展開(kāi)
if(!f){
return 0;? //場(chǎng)景列表不展開(kāi)
}else{
return 3;
}
}
#pragma mark 組頭視圖 高度為60
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 50;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify forIndexPath:indexPath];
cell.backgroundColor = [UIColor blueColor];
return cell;
}