简体   繁体   English

在不重新加载 Tableview 的情况下,使用 Observer 更新已更改的索引单元格值 iOS Swift

[英]Without reloading Tableview, update the changed index cell values using Observer in iOS Swift

In the first time I collect the array values from API response and displayed it in tableview, again I will get the same response from socket and reload the values in table, But here I don't need to reload entire table, I want update the cell's which value has been changed.我第一次从 API 响应中收集数组值并将其显示在 tableview 中,我再次从套接字获得相同的响应并重新加载表中的值,但在这里我不需要重新加载整个表,我想更新单元格的哪个值已更改。

Here Compare the two array's, from which index has changes, just need to update that index row cells only, without reload entire table view.这里比较两个数组,索引有变化,只需要更新索引行单元格,而不需要重新加载整个表视图。 old and new array , CodeSample旧数组和新数组代码示例

But you should be careful if will change some indexPaths in you data stack, if it gonna happen - use tableView.deleteRows or tableView.deleteSections .但是如果会更改数据堆栈中的某些 indexPaths,您应该小心,如果它会发生 - 使用tableView.deleteRowstableView.deleteSections This updates should be qual in table and in dataStack or crash此更新在表和 dataStack 或crash中应该是合格的

let indexPaths = [IndexPath]()
tableView.performBatchUpdates {
    self.tableView.reloadRows(at: indexPaths, with: .none)
}

or或者

tableView.beginUpdates()
tableView.reloadRows(at: indexPaths, with: .none)
tableView.endUpdates()

btw, you can make your indexPaths to update like let indexPaths = tableView.indexPathsForVisibleRows - method's name is speechful, in case if you have socket I suppose it would be helpful since u've got dynamic顺便说一句,你可以让你的 indexPaths 像let indexPaths = tableView.indexPathsForVisibleRows一样更新 - 方法的名字很有趣,如果你有套接字我想它会有所帮助,因为你有动态

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift iOS-如何更改已在屏幕上加载的所有可见单元的TableView单元属性,而无需重新加载数据? - Swift iOS -How to change TableView Cell Properties for All Visible Cells Already Loaded On Screen Without Reloading Data? Swift-更新或在表格视图的部分中插入一行,而无需重新加载所有数据 - Swift - Update or insert a row in a section in a tableview without reloading all the data iOS - Observer 观察 tableView dequeue Reusable Cell - iOS - Observer to observe tableView dequeue Reusable Cell iOS Swift,使用标记在tableview CellForRow之外更新UITableView自定义单元格标签 - iOS Swift, Update UITableView custom cell label outside of tableview CellForRow using tag 如何在Tableview单元格中更新TextLabel iOS Swift - How to update textLabel inside a tableview cell iOS Swift 根据类似状态更新 tableview 中使用的单元格中的按钮,而无需重新加载单元格 - Update a button in a cell used in tableview depending on like status without reloading the cell ios swift 大型 tableview 单元格数据每秒更新一次 - ios swift large tableview cell data update in every second 重新加载数据时 ios swift 4 中的 Tableview 闪烁 - Tableview flickers in ios swift 4 while reloading the data 没有Storyboard的TableView Cell中的iOS Swift Segue - iOS Swift Segue from TableView Cell without Storyboard UITableView InfiniteScrolling 无需在 Swift 中重新加载 TableView - UITableView InfiniteScrolling without reloading TableView in Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM