功能比較簡單,簡單的TableView展開與回收
一、HeadView.m中
1.實(shí)現(xiàn)加載xib文件的方法
+(HeadView *)instanceHeadView
{
NSArray* nibView =? [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil];
return [nibView objectAtIndex:0];
}
2.根據(jù)頭部視圖打開狀態(tài)哈误,旋轉(zhuǎn)箭頭
- (void)setOpen:(BOOL)Open{
NSLog(@"%d",Open);
if (Open) {
[UIView animateWithDuration:0.25
animations:^{
self.RightArrrow.transform = CGAffineTransformMakeRotation(M_PI_2);
}];
}else{
[UIView animateWithDuration:0.25
animations:^{
self.RightArrrow.transform = CGAffineTransformMakeRotation(0);
}];
}
}
二、ViewController.m中
1.headview的點(diǎn)擊方法
- (void)action_tap:(UIGestureRecognizer *)tap {
NSString *section = [NSString stringWithFormat:@"%ld",tap.view.tag - 300];
HeadView*headview =(HeadView*) tap.view;
if ([dic[section] integerValue] == 0) {[dic setObject:@"1" forKey:section];
headview.Open = YES;
}else{//反之關(guān)閉cell[dic setObject:@"0" forKey:section];
headview.Open = NO;
}[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:[section integerValue]] withRowAnimation:UITableViewRowAnimationFade];//有動(dòng)畫的刷新}
demo地址:https://github.com/youweikang/TableView-.git
這里面曾經(jīng)遇到過2個(gè)坑捕虽,聊作記錄
1.第1個(gè)section的row的數(shù)據(jù)不能影響第0個(gè)section的row的數(shù)據(jù);(不能互相干擾坡脐,否則刷新列表崩潰)
2.頭部視圖加載方法不能放在
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section里泄私。我知道你們沒遇到過。