最近在开发过程中,发现的一个问题,当cell重用之后,数据更新,但是里面其中两个是完全一样的数据,所以当button的tag标记写到if判断里面的时候就不会走tag的设置
代码如下:
ssddddddd *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];
if (!cell) {
cell = [[ssddddddd alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseID];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell.button addTarget:self action:@selector(xxxxx:) forControlEvents:UIControlEventTouchUpInside];
cell.button.tag = 1000 + indexPath.section;
}
这种情况就可能出现数据跑偏的问题,后面使用tag的值也会出现变化;
解决方法;
1cell的id的改变,根据section,或者path来标记
2将标记tag写到if外面如下:
ssddddddd *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];
if (!cell) {
cell = [[ssddddddd alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseID];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
[cell.button addTarget:self action:@selector(xxxxx:) forControlEvents:UIControlEventTouchUpInside];
cell.button.tag = 1000 + indexPath.section;
完