折叠cell

折叠cell

在暑假任务3Gshare中用到了折叠cell;
具体效果如下:在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
首先设定两个属性为:tableView和存储cell的元素数据的可变数组。

@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableview1;
@property (nonatomic, strong) NSMutableArray *array;

@end

然后对两个属性进行初始化,注意对tableView1的tag只进行设定,从而通过tag的值来判断cell的展开还是收缩状态。

self.tableview1 = [[UITableView alloc] initWithFrame:CGRectMake(100, 100, 430 - 200, 100)];
    self.tableview1.delegate = self;
    self.tableview1.dataSource = self;
    self.tableview1.tag = 0;
    [self.tableview1 registerClass:[UITableViewCell class] forCellReuseIdentifier:@"1"];
    [self.view addSubview:_tableview1];
    
    _array = [NSMutableArray arrayWithObjects:@"原创作品",@"设计教程",@"设计资料",@"设计师观点", nil];

然后要完成tableView的协议函数:

//获取每组单元格的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   
   
    if (_tableview1.tag == 0) {
   
   
        return 1;
    } else {
   
   
        return 4<
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值