国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

IOS實現展開二級列表效果

2019-10-21 18:53:11
字體:
來源:轉載
供稿:網友

先來看看效果圖

ios,二級展開列表,分組列表,ios展開列表

用法(類似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值為sectionview.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 = CGAffineTransformMakeRotation(-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 = CGAffineTransformMakeRotation(0);  }]; }}

總結

以上就是IOS實現展開二級列表效果的全部內容,希望對大家學習開發IOS能有所幫助。

 


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 合肥市| 陕西省| 清徐县| 项城市| 博白县| 安仁县| 上栗县| 无棣县| 蒙山县| 巴马| 弥渡县| 宜丰县| 凤凰县| 新源县| 云龙县| 三门县| 昔阳县| 花莲市| 富顺县| 高淳县| 竹北市| 龙海市| 巫溪县| 黄大仙区| 隆回县| 德钦县| 馆陶县| 四子王旗| 南丰县| 澎湖县| 曲靖市| 金沙县| 衡南县| 栾川县| 寿光市| 翼城县| 建平县| 杭州市| 卢氏县| 郯城县| 蓬溪县|