IOS實(shí)現(xiàn)展開(kāi)二級(jí)列表效果
先來(lái)看看效果圖

用法(類(lèi)似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];
實(shí)現(xiàn)數(shù)據(jù)源
- (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 @"我是頭部";
}
實(shí)現(xiàn)代理
- (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(@"即將展開(kāi)");
}
- (void)mTableView:(XDMultTableView *)mTableView willCloseHeaderAtSection:(NSInteger)section{
NSLog(@"即將關(guān)閉");
}
- (void)mTableView:(XDMultTableView *)mTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"點(diǎn)擊cell");
}
列表展開(kāi)關(guān)閉的實(shí)現(xiàn)原理
在section header注冊(cè)一個(gè)手勢(shì)
//section header view 設(shè)置tag值為section view.tag = section; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapHeader:)]; [view addGestureRecognizer:tap];
手勢(shì)的響應(yīng)事件
- (void)tapHeader:(UITapGestureRecognizer *) tap {
NSInteger section = tap.view.tag;
NSNumber *sectionObj = [NSNumber numberWithInteger:section];
UIImageView *imageView = (UIImageView *)[tap.view viewWithTag:100];
//_multopenSectionArray 用于記錄每個(gè) section的展開(kāi)和關(guān)閉狀態(tài)
if ([_multopenSectionArray containsObject:sectionObj]) {
NSArray *deleteArray = [self buildDeleteRowWithSection:section];
[_multopenSectionArray removeObject:sectionObj];
//想關(guān)閉的section的所有indexPath
[_tableView deleteRowsAtIndexPaths:deleteArray withRowAnimation:UITableViewRowAnimationFade];
[UIView animateWithDuration:0.3 animations:^{
imageView.transform = CGAffineTransformMakeRotation(-M_PI/2);
}];
}else{
[_multopenSectionArray addObject:sectionObj];
//想展開(kāi)的section的所有indexPath
NSArray *insertArray = [self buildInsertRowWithSection:section];
[_tableView insertRowsAtIndexPaths:insertArray withRowAnimation:UITableViewRowAnimationFade];
[UIView animateWithDuration:0.3 animations:^{
imageView.transform = CGAffineTransformMakeRotation(0);
}];
}
}
總結(jié)
以上就是IOS實(shí)現(xiàn)展開(kāi)二級(jí)列表效果的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)開(kāi)發(fā)IOS能有所幫助。
- IOS展開(kāi)三級(jí)列表效果示例
- iOS多級(jí)列表實(shí)現(xiàn)代碼
- IOS實(shí)現(xiàn)簡(jiǎn)易版的QQ下拉列表
- iOS開(kāi)發(fā)之在列表上方添加水印的方法
- iOS 標(biāo)簽Tag列表的實(shí)現(xiàn)代碼
- ios基于UITableViewController實(shí)現(xiàn)列表
- iOS實(shí)現(xiàn)列表折疊效果
- iOS列表上拉(平滑加載數(shù)據(jù))自動(dòng)加載數(shù)據(jù)的問(wèn)題解決
- iOS實(shí)現(xiàn)從通訊錄中選擇聯(lián)系人
- iOS實(shí)現(xiàn)聯(lián)系人列表功能
相關(guān)文章
詳解iOS應(yīng)用UI開(kāi)發(fā)中的九宮格坐標(biāo)計(jì)算與字典轉(zhuǎn)換模型
這篇文章主要介紹了iOS應(yīng)用UI開(kāi)發(fā)中的九宮格坐標(biāo)計(jì)算與字典轉(zhuǎn)換模型,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下2016-01-01
IOS 出現(xiàn)錯(cuò)誤reason: image not found的解決方案
這篇文章主要介紹了IOS 出現(xiàn)錯(cuò)誤reason: image not found的解決方案的相關(guān)資料,需要的朋友可以參考下2017-05-05
詳解iOS 計(jì)步器的幾種實(shí)現(xiàn)方式
本篇文章主要介紹了詳解iOS 計(jì)步器的幾種實(shí)現(xiàn)方式,詳細(xì)的介紹了兩種可以獲取計(jì)步數(shù)據(jù)的方法,有興趣的可以了解一下2017-08-08
舉例講解iOS開(kāi)發(fā)中拖動(dòng)視圖的實(shí)現(xiàn)
這篇文章主要介紹了舉例講解iOS開(kāi)發(fā)中的拖動(dòng)視圖實(shí)現(xiàn),代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下2015-10-10
IOS App 無(wú)代碼入侵的方法hook詳細(xì)介紹
這篇文章主要介紹了IOS App 無(wú)代碼入侵的方法hook詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下2016-12-12
IOS中自定義類(lèi)中限制使用原生實(shí)例化方法
這篇文章主要介紹了IOS中自定義類(lèi)中限制使用原生實(shí)例化方法的相關(guān)資料,需要的朋友可以參考下2017-09-09

