swift - 我有关于 tableView 的问题。滚动时值变化

标签 swift uitableview ios9.2

我有关于 tableView 的问题。我正在快速开发一个关于聊天模块的项目。我正在从网络服务获取数据。第一次加载 View 时,我的聊天单元看起来很完美。但是当我发送消息或滚动 tableView 时,值会发生变化或丢失。任何人都可以帮我解决这个问题吗?我在这个问题上纠结了很长时间。

最佳答案

我有关于tableView的答案。 scnr

您需要跟踪 tableView 的 dataSource 以及 tableView 本身中数据的更改。

编辑: 假设您的聊天数据是一个字符串数组,按日期排序,最新消息在顶部,在插入数据时,您应该

tableView?.beginUpdates() // signal the tableview a pending update
data.insert(newMessage, atIndex:0) // modify your dataSource's data
tableView?.insertRowsAtIndexPaths([NSIndexPath(0, inSection: 0)], withRowAnimation: .Automatic) // insert the new row in the tableView
tableView?.endUpdates() // commit changes

关于swift - 我有关于 tableView 的问题。滚动时值变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34900318/

相关文章:

ios - 通过 Google 或 Facebook 登录不返回应用程序

swift - 设置 MKMapKit 区域在测试中失败

swift - 以= {}()结尾的变量名称是什么Swift?

ios - 在其他函数中使用位置管理器函数的值

objective-c - 如何使特定的 UITableViewCell 在屏幕上可见,同时在 UITableView 中有更多行

xcode7 - Xcode 7.2 : Failed to Locate or generated signing assets, 通配符应用程序 ID 无法用于创建内部配置文件

swift - 从 Firebase 同步读取

swift - 为什么我不能将 Firebase 实时数据库中的数据显示到 UITableView 中?

objective-c - 转换为使用自动引用计数后不再调用委托(delegate)方法

ios - 如何使用 "sequential finger detection"的新 iOS 9.2 Touch ID 功能