欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

IOS實現(xiàn)展開二級列表效果

 更新時間:2016年08月12日 12:07:48   投稿:daisy  
本文通過實例代碼向大家演示在IOS中如何實現(xiàn)展開二級列表的效果,這個功能效果很好,對于日常開發(fā)APP中很有幫助,下面一起來看看如何實現(xiàn)吧。

先來看看效果圖

用法(類似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];

實現(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 @"我是頭部";
}

實現(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(@"即將展開");
}

- (void)mTableView:(XDMultTableView *)mTableView willCloseHeaderAtSection:(NSInteger)section{
 NSLog(@"即將關(guān)閉");
}

- (void)mTableView:(XDMultTableView *)mTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
 NSLog(@"點擊cell");
}

列表展開關(guān)閉的實現(xiàn)原理
在section header注冊一個手勢

//section header view 設(shè)置tag值為section
view.tag = section;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapHeader:)];
 [view addGestureRecognizer:tap];

手勢的響應(yīng)事件

- (void)tapHeader:(UITapGestureRecognizer *) tap {
 NSInteger section = tap.view.tag;
 NSNumber *sectionObj = [NSNumber numberWithInteger:section];
 UIImageView *imageView = (UIImageView *)[tap.view viewWithTag:100];
 //_multopenSectionArray 用于記錄每個 section的展開和關(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];
  //想展開的section的所有indexPath
  NSArray *insertArray = [self buildInsertRowWithSection:section];
  [_tableView insertRowsAtIndexPaths:insertArray withRowAnimation:UITableViewRowAnimationFade];
  [UIView animateWithDuration:0.3 animations:^{
   imageView.transform = CGAffineTransformMakeRotation(0);
  }];
 }
}

總結(jié)

以上就是IOS實現(xiàn)展開二級列表效果的全部內(nèi)容,希望對大家學(xué)習(xí)開發(fā)IOS能有所幫助。

相關(guān)文章

  • IOS 實現(xiàn)微信自動搶紅包(非越獄IPhone)

    IOS 實現(xiàn)微信自動搶紅包(非越獄IPhone)

    這篇文章主要介紹了IOS 實現(xiàn)微信自動搶紅包(非越獄IPhone)的相關(guān)資料,這里對實現(xiàn)自動搶紅包做一個詳細的實現(xiàn)步驟,需要的朋友可以參考下
    2016-11-11
  • iOS應(yīng)用程序之間的幾種跳轉(zhuǎn)情況詳解

    iOS應(yīng)用程序之間的幾種跳轉(zhuǎn)情況詳解

    這篇文章給大家詳細介紹了iOS應(yīng)用程序之間跳轉(zhuǎn)的幾種情況,包括跳轉(zhuǎn)到另一個程序的主界面、跳轉(zhuǎn)到另一個程序的指定界面以及如何從目標(biāo)程序的非主頁界面回到當(dāng)前(跳轉(zhuǎn)前)程序呢?有需要的朋友們可以下面來一起看看。
    2016-09-09
  • iOS使用WKWebView加載HTML5不顯示屏幕寬度的問題解決

    iOS使用WKWebView加載HTML5不顯示屏幕寬度的問題解決

    這篇文章主要介紹了iOS使用WKWebView加載HTML5不顯示屏幕寬度的問題解決,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-12-12
  • touchesBegan: withEvent: 不執(zhí)行解決

    touchesBegan: withEvent: 不執(zhí)行解決

    這篇文章主要介紹了touchesBegan: withEvent: 不執(zhí)行解決的相關(guān)資料,需要的朋友可以參考下
    2016-12-12
  • iOS 高德地圖仿微信發(fā)送實時位置

    iOS 高德地圖仿微信發(fā)送實時位置

    這篇文章主要介紹了iOS 高德地圖仿微信發(fā)送實時位置,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03
  • iOS App使用SQLite之句柄的定義及數(shù)據(jù)庫的基本操作

    iOS App使用SQLite之句柄的定義及數(shù)據(jù)庫的基本操作

    SQLite中在定義過句柄之后就可以指向數(shù)據(jù)庫,從而利用iOS應(yīng)用程序進行打開或關(guān)閉等各種操作,這里我們就來看一下iOS App使用SQLite之句柄的定義及數(shù)據(jù)庫的基本操作
    2016-06-06
  • iOS開發(fā)中UIDatePicker控件的使用方法簡介

    iOS開發(fā)中UIDatePicker控件的使用方法簡介

    這篇文章主要介紹了iOS開發(fā)中UIDatePicker控件的使用方法簡介,用來處理各種時間日期的選擇,需要的朋友可以參考下
    2015-11-11
  • ios彈幕高效加載實現(xiàn)方式實例代碼

    ios彈幕高效加載實現(xiàn)方式實例代碼

    看到密密麻麻的彈幕第一印象就是怎么樣高效加載來避免卡頓,這篇文章主要介紹了ios彈幕高效加載實現(xiàn)方式實例代碼,有興趣的可以了解一下。
    2017-03-03
  • iOS指紋識別的簡單應(yīng)用

    iOS指紋識別的簡單應(yīng)用

    這篇文章主要為大家詳細介紹了iOS指紋識別的簡單應(yīng)用,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-07-07
  • 詳解iOS本地推送與遠程推送

    詳解iOS本地推送與遠程推送

    這篇文章主要為大家詳細介紹了iOS本地推送與遠程推送,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09

最新評論