我有关于 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/