日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

仿QQ联系人的TableView的折叠与拉伸

發(fā)布時(shí)間:2023/12/20 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 仿QQ联系人的TableView的折叠与拉伸 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

最近手上任務(wù)比較輕,打算把一些之前做一些的簡單的東西再整理整理,優(yōu)化一下,做個(gè)記錄;?

TableView的折疊拉伸主要是在一些聯(lián)系人分組里會(huì)經(jīng)常見到,今天做了一個(gè)簡單的demo,代碼也做了處理,隨拿隨用。

思路整理:

1.根據(jù)數(shù)據(jù)設(shè)置分組

2.設(shè)置折疊/拉伸狀態(tài)標(biāo)識(shí)

3.實(shí)現(xiàn)分組透視圖點(diǎn)擊事件

實(shí)現(xiàn)代碼:

#import "FoldTableViewController.h"

#define STATE @"state"

#define INFO @"info"

@interface FoldTableViewController ()

{

NSMutableArray *_dataArray;//數(shù)據(jù)源數(shù)組

}

@end

@implementation FoldTableViewController

- (void)viewDidLoad {

[super viewDidLoad];

[self setExtraCellLineHidden];

[self requestData];

}

//底部視圖留白

- (void)setExtraCellLineHidden{

UIView *view = [UIView new];

view.backgroundColor = [UIColor clearColor];

[self.tableView setTableFooterView:view];

}

//創(chuàng)建數(shù)據(jù)

- (void)requestData{

/**

假設(shè)有i組數(shù)據(jù),每組有j條內(nèi)容:

每組實(shí)例化一個(gè)可變字典存儲(chǔ)組內(nèi)數(shù)據(jù),STATE對(duì)應(yīng)當(dāng)前狀態(tài)(折疊/拉伸),INFO對(duì)應(yīng)當(dāng)前內(nèi)容;

*/

_dataArray = [[NSMutableArray alloc]init];

for (int i = 0; i < 5; i++) {

NSMutableDictionary *tempDict = [[NSMutableDictionary alloc]init];

NSMutableArray *tempArr = [[NSMutableArray alloc]init];

for (int j = 0; j < 10; j++) {

NSString *infoStr = [NSString stringWithFormat:@"test%d",j];

[tempArr addObject:infoStr];

}

[tempDict setValue:@"1" forKey:STATE];

[tempDict setValue:tempArr forKey:INFO];

[_dataArray addObject:tempDict];

}

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

return _dataArray.count;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

NSString *state = _dataArray[section][STATE];

if ([state isEqualToString:@"0"]) {

return 0;

}

return [_dataArray[section][@"info"] count];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

static NSString *ide = @"myCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ide];

if (!cell) {

cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ide];

}

//取到當(dāng)前cell的內(nèi)容

cell.textLabel.text = _dataArray[indexPath.section][@"info"][indexPath.row];

return cell;

}

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

UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 20)];

headView.tag = 10+section;

headView.backgroundColor = [UIColor grayColor];

UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 20, 20)];

[headView addSubview:imageView];

UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 5, 100, 20)];

titleLabel.text = [NSString stringWithFormat:@"section%ld",section];

titleLabel.textColor = [UIColor whiteColor];

[headView addSubview:titleLabel];

/**在刷新視圖時(shí),根據(jù)當(dāng)前分組的狀態(tài),調(diào)整頭視圖的內(nèi)容視圖

*/

NSDictionary *dict = _dataArray[section];

if ([dict[STATE] isEqualToString:@"1"]) {

imageView.image = [UIImage imageNamed:@"arrow_spread"];

}else{

imageView.image = [UIImage imageNamed:@"arrow_fold"];

}

/**為頭視圖添加輕觸事件

*/

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headViewClick:)];

[headView addGestureRecognizer:tap];

return headView;

}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

return 30;

}

- (void)headViewClick:(UITapGestureRecognizer *)tap{

NSInteger index = tap.view.tag-10;

NSMutableDictionary *dict = _dataArray[index];

/**點(diǎn)擊頭視圖,改變?cè)摻M狀態(tài)

*/

if ([dict[STATE] isEqualToString:@"1"]) {

[dict setValue:@"0" forKey:STATE];

}else{

[dict setValue:@"1" forKey:STATE];

}

/**刷新當(dāng)前點(diǎn)擊分組的數(shù)據(jù)

reloadSections:需要刷新的分組

withRowAnimation:刷新的動(dòng)畫方式

*/

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:index] withRowAnimation:UITableViewRowAnimationNone];

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

[tableView deselectRowAtIndexPath:indexPath animated:YES];

}

轉(zhuǎn)載于:https://juejin.im/post/5a31d4d451882526151a9ac2

總結(jié)

以上是生活随笔為你收集整理的仿QQ联系人的TableView的折叠与拉伸的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 久久天天躁狠狠躁夜夜躁2014 | 中文字幕视频一区二区 | 小辣椒福利视频导航 | 亚洲欧美在线综合 | 丝袜脚交免费网站xx | 日韩精品在线免费 | jzzijzzij亚洲成熟少妇18 欧美www在线观看 | 国产欧美一区二区三区精品酒店 | 午夜精品成人 | 亚洲片国产一区一级在线观看 | 2021天天操| 淫欲少妇| 台湾swag在线观看 | 北条麻妃一区二区三区四区五区 | 亚洲成av人片一区二区梦乃 | 欧美激情四区 | 亚欧洲乱码视频 | 玖玖玖在线观看 | 美女扒开腿让男人操 | 人操人操| 香蕉视频成人在线观看 | 精品国产一区二区三区四区阿崩 | 97人妻精品一区二区 | 中文字幕亚洲无线码在线一区 | 999视频在线播放 | 激情五月亚洲 | 色九九视频 | 国产一级视频在线 | 免费一级suv好看的国产网站 | 欧美xxxx喷水 | 亚洲国产一区二区三区a毛片 | 国产91丝袜在线观看 | 淫人网 | 亚洲精品久久视频 | 老熟妇一区二区三区啪啪 | 日韩精品在线视频免费观看 | 久久亚洲精品中文字幕 | 最好看的2019年中文在线观看 | 免费成人av片 | 久久国产精 | 成人a v视频 | 一级中国毛片 | 中文字幕+乱码+中文 | 中国黄色一级视频 | 欧美v在线 | 亚洲激情视频小说 | 中文精品一区 | www国产精品内射熟女 | 日本理伦片午夜理伦片 | 谁有毛片网站 | 成年网站在线观看 | 国产噜噜噜噜噜久久久久久久久 | 丰满多毛的大隂户视频 | 婷婷久草| 麻豆com | 日本人视频69式jzzij | 国产盗摄精品一区二区酒店 | 伊人狼人综合 | 奇米色综合 | 狠狠97 | 国产高清无密码一区二区三区 | 99这里只有精品视频 | 在线视频日韩欧美 | 日本中文字幕不卡 | 91porn在线| 欧美日韩视频在线播放 | 三级免费黄 | 国产免费内射又粗又爽密桃视频 | av电影一区二区三区 | av网站免费看 | 亚洲乱码久久 | 午夜精品久久久久久久久久久久 | 欧美绿帽合集xxxxx | 激情视频网 | 伊人福利在线 | 艳妇乳肉豪妇荡乳av无码福利 | 欧美精品一区二区三区蜜臀 | 女futa攻玩遍整个后宫 | 亚洲卡一卡二卡三 | 久久91视频 | 欧美激情自拍 | 国产精品12区 | 国产精品免费一区二区三区都可以 | 欧美你懂的| 日韩福利在线视频 | 国产校园春色 | 国产超91| 我和单位漂亮少妇激情 | av高清不卡| 成人做爰免费视频免费看 | 日韩av一区二区在线观看 | 在线免费精品视频 | 欧美人狂配大交3d | 国产淫片av片久久久久久 | 一区二区三区美女 | 一起草国产 | 大粗鳮巴久久久久久久久 | 成人免费超碰 | 久久久久久久久久一区二区三区 |