你的位置:首页 > 软件开发 > 操作系统 > UITableview中怎么找到每个cell

UITableview中怎么找到每个cell

发布时间:2015-11-23 16:00:03
一个朋友问我:我在每个cell中都添加了两个按钮(记为btnA和btnB),点击btnA时,对应的cell中添加一个子控件,再点击btnB时,对应的cell中的子控件就移除,怎么做到? 百度了一下,发现了解决办法:首先,创建btn时,给每个btn加一个tag值//创建cell ...

一个朋友问我:我在每个cell中都添加了两个按钮(记为btnA和btnB),点击btnA时,对应的cell中添加一个子控件,再点击btnB时,对应的cell中的子控件就移除,怎么做到?

 

百度了一下,发现了解决办法:

首先,创建btn时,给每个btn加一个tag值

//创建cell方法-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{  static NSString * iden=@"iden";  _cell=[tableView dequeueReusableCellWithIdentifier:iden];  if (_cell==nil) {    _cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden];  }    UIButton * btnA=[UIButton buttonWithType:UIButtonTypeCustom];  btnA.frame=CGRectMake(0, 0, 50, 20);  btnA.tag = 1000 + indexPath.row;  btnA.backgroundColor=[UIColor greenColor];  [btnA addTarget:self action:@selector(btnBClick:) forControlEvents:UIControlEventTouchUpInside];    [_cell.contentView addSubview:btnA];    UIButton * btnB=[UIButton buttonWithType:UIButtonTypeCustom];  btnB.tag = 2000 + indexPath.row;  btnB.frame=CGRectMake(100, 0, 50, 20);  btnB.backgroundColor=[UIColor redColor];  [btnB addTarget:self action:@selector(btnAClick:) forControlEvents:UIControlEventTouchUpInside];  [_cell.contentView addSubview:btnB];  return _cell;}

原标题:UITableview中怎么找到每个cell

关键词:ie

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