SelfMentionContactsListView.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // SelfMentionContactsListView.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/4/25.
  6. // Copyright © 2019 南鑫林. All rights reserved.
  7. //
  8. import UIKit
  9. class SelfMentionContactsListView: BaseView {
  10. typealias DidSelectRowClosure = (_ indexPath: IndexPath) -> Void
  11. var didSelectRowClosure : DidSelectRowClosure?
  12. typealias EditTransClosure = (_ selfMentionContactsModel:SelfMentionContactsModel, _ listCount: Int) -> Void
  13. var editTransClosure: EditTransClosure?
  14. var selfMentionContactsModels: Array<SelfMentionContactsModel>? {
  15. didSet {
  16. tableView.reloadData()
  17. }
  18. }
  19. override func setupViews() {
  20. addSubview(tableView)
  21. let emptyView = DIYEmptyView.empty(with: kImage(name: "page04"), titleStr: nil, detailStr: "当前暂无数据,请添加新收货人")
  22. emptyView!.contentViewY = kScaleValue(value: 182)
  23. tableView.ly_emptyView = emptyView
  24. tableView.ly_startLoading()
  25. }
  26. override func setupLayouts() {
  27. tableView.snp.makeConstraints { (make) in
  28. make.edges.equalToSuperview()
  29. }
  30. }
  31. lazy var tableView: UITableView = {
  32. let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
  33. tableView.backgroundColor = kf7f8faColor
  34. tableView.delegate = self
  35. tableView.dataSource = self
  36. tableView.separatorStyle = .none
  37. tableView.estimatedRowHeight = 74
  38. return tableView
  39. }()
  40. }
  41. extension SelfMentionContactsListView: UITableViewDelegate,UITableViewDataSource {
  42. func numberOfSections(in tableView: UITableView) -> Int {
  43. return 1
  44. }
  45. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  46. return selfMentionContactsModels?.isEmpty ?? true ? 0 : selfMentionContactsModels?.count ?? 0
  47. }
  48. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  49. let cell = SelfMentionContactsListTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  50. cell.selfMentionContactsModel = selfMentionContactsModels?[indexPath.row]
  51. cell.editClosure = {
  52. [weak self] selfMentionContactsModel in
  53. if let editTransClosure = self?.editTransClosure {
  54. editTransClosure(selfMentionContactsModel, self?.selfMentionContactsModels?.count ?? 0)
  55. }
  56. }
  57. return cell
  58. }
  59. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  60. if let didSelectRowClosure = self.didSelectRowClosure {
  61. didSelectRowClosure(indexPath)
  62. }
  63. }
  64. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  65. return UITableView.automaticDimension
  66. }
  67. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  68. return nil
  69. }
  70. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  71. return 10
  72. }
  73. func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  74. return nil
  75. }
  76. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  77. return 0.0000001
  78. }
  79. }