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

首頁 > 系統 > iOS > 正文

ios tableView 的cell打開收起功能,類似QQ中的cell折疊功能

2019-11-09 18:18:11
字體:
來源:轉載
供稿:網友

通過點擊sectionView實現section下屬的cell關閉或打開,類似QQ聯系人界面的功能。

#import "ViewController.h"#define ALLWIDTH [UIScreen mainScreen].bounds.size.width#define ALLHEIGHT [UIScreen mainScreen].bounds.size.height@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>{    UITableView*tableview;    NSArray *dataArr;    NSMutableArray *isOpenArr;    }@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];        tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 40, ALLWIDTH, ALLHEIGHT-40)];    tableview.delegate =self;    tableview.dataSource = self;    tableview.tableFooterView = [[UIView alloc]init];    [self.view addSubview:tableview];            dataArr = [NSArray array];    dataArr = @[@"cell1",@"cell2",@"cell3",@"cell4",@"cell5"];        isOpenArr = [NSMutableArray array];        for (int i =0; i< dataArr.count; i++) {                [isOpenArr addObject:@"0"];    }    }-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{    return 5;}-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    if([isOpenArr[section] isEqualToString:@"1"])    {        return dataArr.count;    }else{        return 0;    }}-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    NSString *cellstr = @"cell";    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellstr];    if (!cell) {        cell = [tableview dequeueReusableCellWithIdentifier:cellstr forIndexPath:indexPath];    }        cell.textLabel.text = dataArr[indexPath.row];        return cell;}-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{    return 50;}-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{    UIView *view  =[[UIView alloc]init];    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0,ALLWIDTH, 50)];    lable.text =  [NSString stringWithFormat:@"------------第%ld組---------",(long)section];    lable.textColor = [UIColor redColor];    [view addSubview:lable];        //添加點擊手勢    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(topgesture:)];    [view addGestureRecognizer:tap];        view.tag = section;    return view;}-(void)topgesture:(UITapGestureRecognizer*)tap{    NSInteger index = tap.view.tag;        if ([isOpenArr[index] isEqualToString:@"1"]) {                [isOpenArr replaceObjectAtIndex:index withObject:@"0"];    }else{        [isOpenArr replaceObjectAtIndex:index withObject:@"1"];            }    [tableview reloadData];    }-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    [tableview deselectRowAtIndexPath:indexPath animated:YES];    NSLog(@"------================--%ld-----",indexPath.row);}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 怀来县| 临清市| 巢湖市| 肃北| 武邑县| 寿光市| 桐柏县| 财经| 白朗县| 伊川县| 鞍山市| 平顺县| 安岳县| 保德县| 临汾市| 堆龙德庆县| 墨脱县| 毕节市| 凤翔县| 盐边县| 广昌县| 永德县| 涡阳县| 华坪县| 张家港市| 原平市| 砀山县| 汶上县| 绿春县| 县级市| 汉源县| 西平县| 蒲江县| 古田县| 乐清市| 铜梁县| 铜鼓县| 长武县| 博乐市| 卢湾区| 五莲县|