swift reloadRows方法 坑记

起因:

自定义了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

        }

    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值