IMInstantMessageViewController.swift 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // IMInstantMessageViewController.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2020/6/12.
  6. // Copyright © 2020 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. class IMInstantMessageViewController: UITableViewController {
  10. private lazy var viewModel: IMViewModel = {
  11. return IMViewModel()
  12. }()
  13. var instantMsgList: [InstantMessage] = []
  14. override func viewDidLoad() {
  15. super.viewDidLoad()
  16. self.title = "通知消息"
  17. self.tableView.register(UINib(nibName: "IMChatMessageViewCell", bundle: nil), forCellReuseIdentifier: "IMChatMessageViewCell")
  18. self.tableView.separatorStyle = .none
  19. self.tableView.rowHeight = UITableView.automaticDimension
  20. self.tableView.estimatedRowHeight = 144
  21. self.tableView.backgroundColor = UIColor(hex: "#f3f3f3")
  22. }
  23. override func viewDidAppear(_ animated: Bool) {
  24. self.scrollMessageToBottom()
  25. }
  26. //刷新tableview 滚动到底部
  27. private func scrollMessageToBottom() {
  28. DispatchQueue.main.async {
  29. if self.instantMsgList.count > 0 {
  30. self.tableView.scrollToRow(at: IndexPath(row: self.instantMsgList.count-1, section: 0), at: .bottom, animated: true)
  31. }
  32. }
  33. }
  34. // MARK: - Table view data source
  35. override func numberOfSections(in tableView: UITableView) -> Int {
  36. return 1
  37. }
  38. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  39. return self.instantMsgList.count
  40. }
  41. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  42. if let cell = tableView.dequeueReusableCell(withIdentifier: "IMChatMessageViewCell", for: indexPath) as? IMChatMessageViewCell {
  43. cell.setInstantContent(item: self.instantMsgList[indexPath.row])
  44. return cell
  45. }
  46. return UITableViewCell()
  47. }
  48. }