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

iOS實現(xiàn)列表折疊效果

 更新時間:2020年02月21日 08:36:26   作者:Robert火山  
這篇文章主要為大家詳細(xì)介紹了iOS實現(xiàn)列表折疊效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了iOS實現(xiàn)列表折疊效果的具體代碼,供大家參考,具體內(nèi)容如下

實現(xiàn)列表折疊效果其實比較簡單,點擊列表頭部的時候,把返回列表行數(shù)設(shè)為 0,就是收起列表;再次點擊列表頭部,顯示列表的行數(shù),就展開了列表。

#import "TableDownUpVC.h"
#import "TableViewCell_TableSelect.h"

@interface TableDownUpVC ()
{
 NSMutableDictionary *dicSelet;
 NSArray *arrData;
 NSMutableArray *arrStatus;
 NSInteger selectFlag;

 NSMutableDictionary *dictShow;
}

@property (nonatomic, strong) UIImageView *imgArror;

@end

@implementation TableDownUpVC

- (void)viewDidLoad {
 [super viewDidLoad];
 self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
 self.title = @"列表折疊效果";

 dictShow = [[NSMutableDictionary alloc] init];
 arrStatus = [[NSMutableArray alloc] init];

 NSDictionary *dict0 = @{@"section":@"頭部0",
       @"content":@[@{@"title":@"Section0",@"subTitle":@"Row0",@"avator":@"user_default_blue"},
           @{@"title":@"Section0",@"subTitle":@"Row1",@"avator":@"user_default_blue"},
           @{@"title":@"Section0",@"subTitle":@"Row2",@"avator":@"user_default_blue"}]};

 NSDictionary *dict1 = @{@"section":@"頭部1",
       @"content":@[@{@"title":@"Section1",@"subTitle":@"Row0",@"avator":@"user_default_blue"},
           @{@"title":@"Section1",@"subTitle":@"Row1",@"avator":@"user_default_blue"},
           @{@"title":@"Section1",@"subTitle":@"Row2",@"avator":@"user_default_blue"}]};

 NSDictionary *dict2 = @{@"section":@"頭部2",
       @"content":@[@{@"title":@"Section2",@"subTitle":@"Row0",@"avator":@"user_default_blue"},
           @{@"title":@"Section2",@"subTitle":@"Row1",@"avator":@"user_default_blue"},
           @{@"title":@"Section2",@"subTitle":@"Row2",@"avator":@"user_default_blue"}]};

 arrData = @[dict0,dict1,dict2];

 dicSelet = [[NSMutableDictionary alloc] init];

 //初始化選中狀態(tài)(默認(rèn)都不選擇)
 for (NSInteger i=0; i<arrData.count; i++) {
  NSArray *content = arrData[i][@"content"];
  NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
  for (NSInteger j=0; j<content.count; j++) {
   [dict setObject:@"0" forKey:STR_NUM(j)];
  }
  [arrStatus addObject:dict];
 }

 //初始化列表頭部折疊狀態(tài)
 for (NSInteger i=0; i<arrData.count; i++) {
  [dictShow setObject:@"0" forKey:STR_NUM(i)];
 }
}

#pragma mark - TableViewDataSource,UITableViewDelegate 擴展

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
 return arrData.count;
}

- (NSInteger)tableViewEx:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
 NSString *isShow = dictShow[STR_NUM(section)];
 if ([isShow isEqualToString:@"0"]) {
  NSArray *arr = arrData[section][@"content"];
  return arr.count;
 } else {
  return 0;
 }
}

- (CGFloat)tableViewEx:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
 return 60;
}

- (UITableViewCell *)tableViewEx:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
 static NSString * identifier = @"cellIdentifier";
 TableViewCell_TableSelect *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
 cell.selectionStyle = UITableViewCellSelectionStyleNone;
 if (cell == nil) {
  cell = [[TableViewCell_TableSelect alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
 }
 [cell setDictInfo:arrData[indexPath.section][@"content"][indexPath.row]];
 [cell setAccessoryImage:arrStatus[indexPath.section][STR_NUM(indexPath.row)]];

 return cell;
}

- (void)tableViewEx:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
 NSMutableDictionary *dict = arrStatus[indexPath.section];
 NSString *str = dict[STR_NUM(indexPath.row)];
 if ([str isEqualToString:@"0"]) {
  [dict setValue:@"1" forKey:STR_NUM(indexPath.row)];
 } else {
  [dict setValue:@"0" forKey:STR_NUM(indexPath.row)];
 }
 [self.tableView reloadData];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
 return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
 return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{

 UIView *headerView = [UICommonCtrl commonViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50) color:kColor_White];

 UILabel *title = [UICommonCtrl commonLabelWithFrame:CGRectMake(10, 15, 200, 20)
             text:arrData[section][@"section"]
             color:kColor_Black
             font:kFont_Large
           textAlignment:NSTextAlignmentLeft];
 [headerView addSubview:title];

 _imgArror = [UICommonCtrl commonImageViewWithFrame:CGRectMake(SCREEN_WIDTH-20, 22.5, 10, 5) image:nil];
 [headerView addSubview:_imgArror];

 NSString *str = [dictShow objectForKey:STR_NUM(section)];
 if ([str isEqualToString:@"0"]) {
  _imgArror.image = [UIImage imageNamed:@"icon_down"];
 } else {
  _imgArror.image = [UIImage imageNamed:@"icon_up"];
 }

 @weakify(self)
 UIButton *btn = [UICommonCtrl commonButtonWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)
             text:@""
             color:kColor_Black
             font:kFont_Large
          backgroundImage:nil
             block:^(UIButton *btn) {
              @strongify(self)
              NSString *str = [dictShow objectForKey:STR_NUM(section)];
              if ([str isEqualToString:@"0"]) {
               [dictShow setValue:@"1" forKey:STR_NUM(section)];
              } else {
               [dictShow setValue:@"0" forKey:STR_NUM(section)];
              }
              [self refreshSection:section];

             }];
 [headerView addSubview:btn];


 for (NSInteger i=0; i<2; i++) {
  UIView *line = [UICommonCtrl commonLineViewWithFrame:CGRectMake(0, (50-LINE_SIZE)*i, SCREEN_WIDTH, LINE_SIZE) color:kColor_Line];
  [headerView addSubview:line];
 }

 return headerView;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
 UIView *footerView = [UICommonCtrl commonViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10) color:kColor_Background];
 return footerView;
}

- (void)refreshSection:(NSInteger)section
{
 NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:section];
 [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
}

@end

效果圖

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • IOS中的webView加載HTML

    IOS中的webView加載HTML

    在日常開發(fā)中,我們?yōu)榱诵蕰玫胶芏嗪芏嗟腤ebView,比如在做某個明細(xì)頁面的時候我們返回給你的可能是一個html字符串,我們就需要將當(dāng)前字符串展示到webView上面,所以我們對HTML標(biāo)簽需要有一定的認(rèn)識,下面我們來一起用html標(biāo)簽和JS寫一個打地鼠游戲
    2016-02-02
  • Swift中的HTTP請求體Request Bodies使用示例詳解

    Swift中的HTTP請求體Request Bodies使用示例詳解

    這篇文章主要為大家介紹了Swift中的HTTP請求體Request Bodies使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-02-02
  • iOS Remote Notification遠程消息推送處理

    iOS Remote Notification遠程消息推送處理

    這篇文章主要為大家詳細(xì)介紹了iOS Remote Notification遠程消息推送處理,感興趣的小伙伴們可以參考一下
    2016-09-09
  • 超全的iOS各種設(shè)備信息獲取方法總結(jié)(包括iPhone8/iPhone X)

    超全的iOS各種設(shè)備信息獲取方法總結(jié)(包括iPhone8/iPhone X)

    這篇文章主要給大家介紹了關(guān)于iOS各種設(shè)備信息獲取方法,iPhone8/iPhone X的后驅(qū)詳細(xì)信息也已更新,文中給出了詳細(xì)的示例代碼供大家參考學(xué)習(xí),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-12-12
  • iOS將時間NSDate轉(zhuǎn)化為毫秒時間戳的方法示例

    iOS將時間NSDate轉(zhuǎn)化為毫秒時間戳的方法示例

    這篇文章主要給大家介紹了關(guān)于iOS將時間NSDate轉(zhuǎn)化為毫秒時間戳的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-08-08
  • iOS中TableView如何統(tǒng)一數(shù)據(jù)源代理詳解

    iOS中TableView如何統(tǒng)一數(shù)據(jù)源代理詳解

    這篇文章主要給大家介紹了關(guān)于iOS中TableView如何統(tǒng)一數(shù)據(jù)源代理的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-07-07
  • iOS沙盒視頻縮略圖及保存本地代碼

    iOS沙盒視頻縮略圖及保存本地代碼

    這篇文章主要為大家詳細(xì)介紹了iOS沙盒視頻縮略圖及保存本地的代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • iOS如何為導(dǎo)航欄添加播放動畫

    iOS如何為導(dǎo)航欄添加播放動畫

    這篇文章主要為大家詳細(xì)介紹了iOS如何為導(dǎo)航欄添加播放動畫的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • 學(xué)習(xí)iOS自定義導(dǎo)航控制器UINavigationController

    學(xué)習(xí)iOS自定義導(dǎo)航控制器UINavigationController

    這篇文章主要為大家詳細(xì)介紹了iOS自定義導(dǎo)航控制器UINavigationController,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • iOS開發(fā)retina屏幕下的點與像素關(guān)系詳解

    iOS開發(fā)retina屏幕下的點與像素關(guān)系詳解

    這篇文章主要為大家介紹了iOS開發(fā)retina屏幕下的點與像素關(guān)系詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-07-07

最新評論