起因:
自定义了2个cell
其中一个cell 点击后调整布局,我使用的是reloadRows 然后把indexpath放到数组里面
发现抖动一下,开始没当回事
后来发现 创建tbv后第一次点击,布局变化都是没有效果的,只有2+次以后才有效果,这就困扰了我
后来调试发现init方法执行了2次
也就是dequeue方法调用了2次
复用池里面没有。。。。这个,所以又创建了,我第一次点击就又创建了一次view所有布局没有变化,以后 池子里就有了
but 这不是我想要的效果
--------
后来直接不用局部刷新,换成全局刷新,就解决这个问题了。。。
原因:
reloadRows 方法 会导致复用池发生变化,cell混乱抖动....
代码:
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) makeUI() // 执行2次 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.section == 0 && indexPath.row == 1 { let cell = tableview.dequeueReusableCell(withIdentifier: ImportMnemonicRouterCellInd) as! ImportMnemonicRouterCell // 失去了本意效果 let arr = dataArray?[indexPath.section] cell.model = arr?[indexPath.row] cell.selectionStyle = UITableViewCell.SelectionStyle.none return cell }else{ let cell = tableview.dequeueReusableCell(withIdentifier: ImportCreateRouterCellInd) as! ImportCreateRouterCell let arr = dataArray?[indexPath.section] cell.model = arr?[indexPath.row] cell.selectionStyle = UITableViewCell.SelectionStyle.none return cell } }