星空网 > 软件开发 > 操作系统

UITbaleView上按钮的单选

设置Id属性,标记是哪个cell

@property (nonatomic,assign)NSInteger Id;

设置一个普通状态和选中状态图片不同的按钮

 _choose = [[UIButton alloc]init];    [_choose setImage:[UIImage imageNamed:@"about_未勾选"] forState:UIControlStateNormal];    [_choose setImage:[UIImage imageNamed:@"about_勾选"] forState:UIControlStateSelected];    [_choose addTarget:self action:@selector(choosePressed:) forControlEvents:UIControlEventTouchUpInside];    [self.contentView addSubview:_choose];

- (void)layoutSubviews {  _choose.frame = CGRectMake(10, 120+wei_tiao, 20, 20);}

设置一个可调整选中或者为选中的方法

- (void)setChecked:(BOOL)checked {  if (checked) {    _choose.selected = YES;  }else {    _choose.selected = NO;  }}

cell上按钮的单击事件

/** * 选择勾选 * * @param sender 按钮 */- (void)choosePressed:(UIButton *)sender {  sender.selected = YES;  if (_chooseBlock) {    _chooseBlock(self.Id);  }}

设置一个全局变量来判定点了哪一个cell

  NSInteger _cellIndex;

 

tableView代理:- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {  ShippingAddressCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"];  cell.selectionStyle = UITableViewCellSelectionStyleNone;  cell.Id = indexPath.row;  if (_cellIndex == indexPath.row) {    [cell setChecked:YES];  }else {    [cell setChecked:NO];  }  [cell setChooseBlock:^(NSInteger index) {    _cellIndex = index;    [_tableView reloadData];  }];  return cell;}

效果图:

 

UITbaleView上按钮的单选

ie
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

开拓印度市场必备!神秘印度之认证篇:https://www.ikjzd.com/articles/98216
拥有3000时尚大V的潮牌电商在纽交所上市了!:https://www.ikjzd.com/articles/98217
开拓印度市场必备!神秘印度之税务篇:https://www.ikjzd.com/articles/98218
亚马逊如何开发高利润产品?就靠这几招!:https://www.ikjzd.com/articles/98219
深入剖析:阿里巴巴国际站P4P着陆页offer和premium!:https://www.ikjzd.com/articles/98221
必看:做外贸千万不可忽视这几个“税”:https://www.ikjzd.com/articles/98222
长治婚庆女司仪和主持人:https://www.vstour.cn/a/366176.html
北京丰台区水上乐园哪家好玩?:https://www.vstour.cn/a/366177.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流