国产探花免费观看_亚洲丰满少妇自慰呻吟_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);}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 古蔺县| 浙江省| 萨嘎县| 交口县| 濮阳县| 察隅县| 荔浦县| 桂阳县| 沙坪坝区| 曲沃县| 永州市| 潜山县| 砀山县| 晋州市| 和龙市| 彭阳县| 霞浦县| 理塘县| 珠海市| 十堰市| 隆安县| 贵溪市| 山东| 常州市| 舟山市| 辽阳市| 建昌县| 永康市| 阿坝县| 隆安县| 新泰市| 刚察县| 宁国市| 德清县| 延寿县| 兴和县| 子长县| 榆林市| 同仁县| 嘉荫县| 夹江县|