选中多个cell (cell 中的Button)

1.声明一个数组(用来放选中的cell)

@property (nonatomic, strong) NSMutableArray *selectIndexs;

2.*然后初始化

self.selectIndexs = [[NSMutableArray alloc] init];

3.然后在tableView的代理中这样写

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ShowAreaCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ShowAreaCell"];
        if (!cell) {
            cell = [[ShowAreaCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ShowAreaCell"];
        }
    cell.nameLabel.text = self.tabArray[indexPath.row];
    cell.selectedButton.selected = [self.selectIndexs containsObject:indexPath];
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if ([self.selectIndexs containsObject:indexPath]) {
        [self.selectIndexs removeObject:indexPath];
    } else {
        [self.selectIndexs addObject:indexPath];
    }
    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    
}

就可以啦~

!
截屏2020-04-21下午6.06.43.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容