做单选按钮

主要是在模型里面设一个属性isSelected

@protocol DBButtonDelegate <NSObject>

- (void)didSelectedButton:(UITableViewCell *)cell;

@end

- (void)mainBtnClick {
    [self.delegate didSelectedButton:self];
}

- (void)didSelectedButton:(UITableViewCell *)cell {
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
    NSInteger index = indexPath.row;
    self.mainID = index;
    for (NSInteger i = 0; i < _viewModel.products.count; i++) {
        DBProduct *product = _viewModel.products[i];
        if (i == index) {
            product.isSelected = YES;
        } else {
            product.isSelected = NO;
        }
    }
    [self.tableView reloadData];
}

推荐阅读更多精彩内容