IHActivityHistoryView.swift 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // IHActivityHistoryView.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2019/12/19.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. import ESPullToRefresh
  10. let kNotifactionIHActivityHistoryViewGetlogList = "kNotifactionIHActivityHistoryViewGetlogList"
  11. protocol IHActivityHistoryViewDelegate : NSObjectProtocol{
  12. func tableViewEsAddPullToRefresh()
  13. func tableViewEsAddInfiniteScrolling()
  14. }
  15. class IHActivityHistoryView: UIView {
  16. weak var delegate : IHActivityHistoryViewDelegate?
  17. var logList:[LogData]?
  18. lazy var tableView: UITableView = {
  19. let tableView = UITableView(frame: .zero, style: .plain)
  20. tableView.delegate = self
  21. tableView.dataSource = self
  22. tableView.allowsSelection = true
  23. tableView.separatorStyle = .none
  24. tableView.register(UINib(nibName: "IHActivityHistoryCell", bundle: nil), forCellReuseIdentifier: "cell")
  25. return tableView
  26. }()
  27. override init(frame: CGRect) {
  28. super.init(frame: frame)
  29. addSubview(tableView)
  30. NotificationCenter.default.addObserver(self, selector: #selector(notifyLoglist), name: NSNotification.Name(kNotifactionIHActivityHistoryViewGetlogList), object: nil)
  31. //设置下滑刷新,上拉加载更多
  32. let header = KKWRefreshHeaderAnimator(frame: CGRect.zero)
  33. let footer = ESRefreshFooterAnimator(frame: CGRect.zero)
  34. //下拉刷新
  35. tableView.es.addPullToRefresh(animator: header) {
  36. self.delegate?.tableViewEsAddPullToRefresh()
  37. }
  38. //上拉加载更多
  39. tableView.es.addInfiniteScrolling(animator: footer) {
  40. self.delegate?.tableViewEsAddInfiniteScrolling()
  41. }
  42. }
  43. func endRefresh(){
  44. tableView.es.stopPullToRefresh()
  45. tableView.es.stopLoadingMore()
  46. }
  47. required init?(coder: NSCoder) {
  48. fatalError("init(coder:) has not been implemented")
  49. }
  50. override func layoutSubviews() {
  51. super.layoutSubviews()
  52. self.tableView.frame = self.bounds
  53. }
  54. @objc func notifyLoglist(_ notif: Notification) {
  55. let _loglist = notif.object as! [LogData]?
  56. self.logList = _loglist
  57. self.tableView.reloadData()
  58. }
  59. deinit {
  60. NotificationCenter.default.removeObserver(self)
  61. }
  62. }
  63. extension IHActivityHistoryView:UITableViewDelegate,UITableViewDataSource{
  64. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  65. return logList?.count ?? 0
  66. }
  67. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  68. let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! IHActivityHistoryCell
  69. cell.selectionStyle = .none
  70. cell.log = logList![indexPath.row]
  71. return cell
  72. }
  73. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  74. return 104
  75. }
  76. }