首页 > 解决方案 > 重新加载表格视图单元格时表格视图单元格闪烁

问题描述

重新加载单个单元格时,表格视图单元格会闪烁。每当 BLE 回调到来时,我想重新加载表格视图单元格。这按预期工作。但是,如果滚动并按住表格视图,则该时间视图单元格会闪烁。

同样的场景,我尝试过没有 BLE 扫描的静态数据,我每秒都在运行计时器并重新加载表格单元格,这次单元格没有闪烁。当我滚动并按住表格视图时,我观察到计时器正在停止,直到我释放表格视图。

但在 BLE 场景中,如果滚动并按住,BLE 回调也会不断出现。

请帮助我处理 BLE 回调案例,以停止表格视图单元格在滚动时闪烁并保持表格视图。

reloadTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(reloadTableViewCells), userInfo: nil, repeats: true)

@objc func reloadTableViewCells(_ name: String) {
    if let index = myArray.firstIndex(where: {name == $0}) {
          self.myArray[index] = name
          self.tableViewRx.reloadRows(at: [IndexPath(row: index, section: 0)], with: .none)
    } else {
         myArray.append(name)
         self.reloadTableView()
    }
}
func scanForBLEDevices() {
    scanBleDevices(allowDuplicates: true, peripheralUUIDString: nil, callback: reloadTableViewCellsOnBleScan)
reloadTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(reloadTableViewCells), userInfo: nil, repeats: true)
}

@objc func reloadTableViewCellsOnBleScan(_ name: String) {
    if let index = myArray.firstIndex(where: {name == $0}) {
          self.myArray[index] = name
          self.tableViewRx.reloadRows(at: [IndexPath(row: index, section: 0)], with: .none)
    } else {
         myArray.append(name)
         self.reloadTableView()
    }
}

预期的结果是,当我滚动并按住表格视图时,表格视图单元格应该停止闪烁。

标签: iosuikitbluetooth-lowenergyswift5

解决方案


推荐阅读