先來看看後果圖

用法(相似UITableView)
初始化XDMultTableView
#import "XDMultTableView.h" ... @property(nonatomic, readwrite, strong)XDMultTableView *tableView; _tableView = [[XDMultTableView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64)]; _tableView.openSectionArray = [NSArray arrayWithObjects:@1,@2, nil]; _tableView.delegate = self; _tableView.datasource = self; _tableView.backgroundColor = [UIColor whiteColor]; [self.view addSubview:_tableView];
完成數據源
- (NSInteger)mTableView:(XDMultTableView *)mTableView numberOfRowsInSection:(NSInteger)section{
return 5;
}
- (XDMultTableViewCell *)mTableView:(XDMultTableView *)mTableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"cell";
UITableViewCell *cell = [mTableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
UIView *view = [[UIView alloc] initWithFrame:cell.bounds] ;
view.layer.backgroundColor = [UIColor whiteColor].CGColor;
view.layer.masksToBounds = YES;
view.layer.borderWidth = 0.3;
view.layer.borderColor = [UIColor lightGrayColor].CGColor;
cell.backgroundView = view;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(XDMultTableView *)mTableView{
return 6;
}
-(NSString *)mTableView:(XDMultTableView *)mTableView titleForHeaderInSection:(NSInteger)section{
return @"我是頭部";
}
完成署理
- (CGFloat)mTableView:(XDMultTableView *)mTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 50;
}
- (CGFloat)mTableView:(XDMultTableView *)mTableView heightForHeaderInSection:(NSInteger)section{
return 40;
}
- (void)mTableView:(XDMultTableView *)mTableView willOpenHeaderAtSection:(NSInteger)section{
NSLog(@"行將睜開");
}
- (void)mTableView:(XDMultTableView *)mTableView willCloseHeaderAtSection:(NSInteger)section{
NSLog(@"行將封閉");
}
- (void)mTableView:(XDMultTableView *)mTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"點擊cell");
}
列表睜開封閉的完成道理
在section header注冊一個手勢
//section header view 設置tag值為section view.tag = section; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithtarget:self action:@selector(tapHeader:)]; [view addGestureRecognizer:tap];
手勢的呼應事宜
- (void)tapHeader:(UITapGestureRecognizer *) tap {
NSInteger section = tap.view.tag;
NSNumber *sectionObj = [NSNumber numberWithInteger:section];
UIImageView *imageView = (UIImageView *)[tap.view viewWithtag:100];
//_multopenSectionArray 用於記載每一個 section的睜開和封閉狀況
if ([_multopenSectionArray containsObject:sectionObj]) {
NSArray *deleteArray = [self buildDeleteRowWithSection:section];
[_multopenSectionArray removeObject:sectionObj];
//想封閉的section的一切indexPath
[_tableView deleteRowsAtIndexPaths:deleteArray withRowAnimation:UITableViewRowAnimationFade];
[UIView animateWithDuration:0.3 animations:^{
imageView.transform = CGAff.netransformMakeRotation(-M_PI/2);
}];
}else{
[_multopenSectionArray addObject:sectionObj];
//想睜開的section的一切indexPath
NSArray *insertArray = [self buildInsertRowWithSection:section];
[_tableView insertRowsAtIndexPaths:insertArray withRowAnimation:UITableViewRowAnimationFade];
[UIView animateWithDuration:0.3 animations:^{
imageView.transform = CGAff.netransformMakeRotation(0);
}];
}
}
總結
以上就是IOS完成睜開二級列表後果的全體內容,願望對年夜家進修開辟IOS能有所贊助。
【IOS完成睜開二級列表後果】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!