ios - 重新加载表格视图单元格时表格视图单元格闪烁
问题描述
重新加载单个单元格时,表格视图单元格会闪烁。每当 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()
}
}
预期的结果是,当我滚动并按住表格视图时,表格视图单元格应该停止闪烁。
解决方案
推荐阅读
- javascript - 如何使用 HTML 表中的按钮删除 Firebase 数据库中的数据
- user-interface - Redis 网络应用程序
- c# - 如何用糟糕的 wsdl 包装一个慢速的肥皂网络服务,以便在逻辑应用程序中使用?
- google-apps-script - 我可以使用 Apps 脚本在文档文档中创建日期选择器吗?
- python - 即使使用 QThread,pyqt5 GUI 也会冻结
- java - 从 docker 容器访问 localhost
- node.js - “路径”参数必须是字符串类型。在捆绑的节点快递应用程序上收到类型号 (0)
- kotlin - Kotlin Glide 给出错误:Request throwed uncaught throwable
- css - 如何在 Django 中的 form.ImageFiled 上使用 CSS?
- angular - 材料自动完成不适用于 Angular 中的 post API