自定义的Cell的赋值

来源:互联网 发布:excel 显示重复数据 编辑:程序博客网 时间:2024/06/04 18:23


1. 先来看一下我在建表的时候禁用 cell重用机制(为了避免cell内容重复显示),   结果发现 在后面改变_addBtn的 tittle的时候竟然改不了, 晕。。。。 注意:我用的禁用cell 判断条件是cell != nil

也就是说在刷表的时候会将之前建的_addBtn覆盖。解决办法:看下面:二、方法; 


一 . 禁用cell重用机制

    cell=[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:ID];

        if (cell !=nil)

        {

             _linkageDeviceLable=[[UILabelalloc]initWithFrame:CGRectMake(_triggerLable.left,0,80,60)];

            _linkageDeviceLable.text=@"联动设备";

            _linkageDeviceLable.font=[UIFontboldSystemFontOfSize:18];

           // _linkageDeviceLable.enabled=NO;

            //_linkageDeviceLable.backgroundColor=[UIColor redColor];

            [cell.contentViewaddSubview:_linkageDeviceLable];

            

            _addBtn=[UIButtonbuttonWithType:UIButtonTypeCustom];

            _addBtn.frame=CGRectMake(_reSwitch.left,_linkageDeviceLable.top,_reSwitch.width,_linkageDeviceLable.height);

            [_addBtnsetTitle:@"添加"forState:UIControlStateNormal];

            [_addBtnsetTitleColor:[UIColorblackColor] forState:UIControlStateNormal];

            _addBtn.titleLabel.font =[UIFontboldSystemFontOfSize:17];

            [_addBtnaddTarget:selfaction:@selector(addDeviceAction)forControlEvents:UIControlEventTouchUpInside];

             [cell.contentViewaddSubview:_addBtn];

          

          }

    

        return cell;

    }


二、 方法

_addBtn设置tag值,

UITableViewCell *cell=[_tableViewcellForRowAtIndexPath:indexpath];

    UILabel *newAliaslable=[cell.contentViewviewWithTag:2016+indexpath.row];

     UILabel *newMaclable=[cell.contentViewviewWithTag:6102+indexpath.row];


重新赋值的时候就OK了;



0 0
原创粉丝点击