我有關於tableView的問題。我正在使用聊天模塊快速開展一個項目。我從Web服務獲取數據。當視圖加載時,我的聊天室第一次顯示完美。但是當我發送消息或滾動tableView時,數值會改變或丟失。任何人都可以幫助我請這個。我在這個問題上陷入了很長時間。我有關於tableView的問題。滾動值的變化
0
A
回答
1
我有關於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
+0
你能解釋一下嗎 –
+0
我的確編輯了我的答案,包括有關在問題和某些快捷方式中缺少的代碼的推測。 – SmokeDispenser
0
您的數據源應與之配合tableView索引.ie應該有一個規則來找出應該顯示給出的消息和tableView的IndexPath。最簡單的規則是假定你的tableView只包含1個部分,你的dataSource中的indexOf消息應該等於IndexPath.Row。例如,您要發送應添加到您的tableView
dataSource.append(newMessage)
tableView.insertRowsAtIndexPaths([NSIndexPath(0, inSection: 0)], withRowAnimation: .Automatic)
,並在你的cellForRowAtIndexPath委託方法的底部
let message = dataSource[indexPath.row]
let cell = tableView.dequeueReusableCellWithIdentifier("MessageCell", forIndexPath: indexPath)
// then use the message to populate the cell then return cell
return cell
相關問題
- 1. 變化的JavaFX的TableView垂直滾動條值編程
- 2. CSS3關於變換動畫的問題
- 3. 關於物化的問題
- 4. 問題與滾動tableview與定製tableviewcell
- 5. 我有一個jQuery的滾動問題
- 6. 關於變量值的變化。
- 7. 我有關於rootview掛起的問題
- 8. 我有幾個關於Authorize.Net的問題
- 9. 我有關於topviewcontroller的問題
- 10. 當我滾動我的tableview崩潰
- 11. 問題與我的tableView GROUPED
- 12. Javascript變量滾動問題
- 13. 關於滾動多個用戶控件的方法的問題
- 14. EXC_BAD_ACCESS滾動的TableView
- 15. 圖像變化時,我滾動的GridView
- 16. 關於初始化問題
- 17. 問題關於C#優化
- 18. 我有幾個關於SslStream類和關於證書的問題
- 19. 滾動動態TableView時全局變量不再初始化(iOS)
- 20. 關於我的點火開關問題?
- 21. 沒有圖像變化的滾動
- 22. 關於在XNA中滾動背景的問題
- 23. 關於100%高度和滾動條的佈局問題-Y
- 24. 關於JS全頁滾動佈局的響應問題
- 25. 關於android的onsen ui carousel滾動問題
- 26. SQL:關於查詢優化的問題
- 27. 關於Qt國際化的問題
- 28. 關於C++優化的問題
- 29. 關於序列化的問題
- 30. 具有固定標題和滾動問題的Datagrid滾動條
你可以發佈你正在使用的代碼創建一個新的消息? –