CircleCommentListCommentReplyTableViewCell.swift 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // CircleCommentListCommentReplyTableViewCell.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/10/17.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. class CircleCommentListCommentReplyTableViewCell: UITableViewCell {
  10. class func cellWith(tableView:UITableView,indexPath:IndexPath) -> CircleCommentListCommentReplyTableViewCell {
  11. let ID = "CircleCommentListCommentReplyTableViewCell"
  12. tableView.register(CircleCommentListCommentReplyTableViewCell.self, forCellReuseIdentifier: ID)
  13. let cell : CircleCommentListCommentReplyTableViewCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! CircleCommentListCommentReplyTableViewCell
  14. cell.indexPath = indexPath
  15. return cell
  16. }
  17. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  18. super.init(style: style, reuseIdentifier: reuseIdentifier)
  19. setupViews()
  20. setupLayouts()
  21. }
  22. required init?(coder aDecoder: NSCoder) {
  23. fatalError("init(coder:) has not been implemented")
  24. }
  25. var indexPath: IndexPath? {
  26. didSet {
  27. }
  28. }
  29. func setupViews() {
  30. self.selectionStyle = .none
  31. backgroundColor = UIColor.white
  32. addSubview(tableView)
  33. }
  34. func setupLayouts() {
  35. tableView.snp.makeConstraints { (make) in
  36. make.top.bottom.equalToSuperview()
  37. make.left.equalTo(62)
  38. make.right.equalTo(-14)
  39. }
  40. }
  41. private lazy var tableView: UITableView = {
  42. let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
  43. tableView.separatorStyle = .none
  44. tableView.backgroundColor = kf7f8faColor
  45. tableView.dataSource = self
  46. tableView.delegate = self
  47. tableView.isScrollEnabled = false
  48. tableView.cornerRadius = 4
  49. tableView.masksToBounds = true
  50. return tableView
  51. }()
  52. private lazy var footerView: CircleCommnetListRepleyFooterView = {
  53. let footerView = CircleCommnetListRepleyFooterView(frame: CGRect(x: 0, y: 0, width: kScreenWidth - 101 - 21, height: 40))
  54. return footerView
  55. }()
  56. var communityCircleCommentListModel : CommunityCircleCommentListModel? {
  57. didSet {
  58. if communityCircleCommentListModel?.replyCount ?? 0 > 2 {
  59. footerView.communityCircleCommentListModel = communityCircleCommentListModel
  60. tableView.tableFooterView = footerView
  61. }
  62. tableView.reloadData()
  63. }
  64. }
  65. }
  66. extension CircleCommentListCommentReplyTableViewCell : UITableViewDelegate,UITableViewDataSource {
  67. func numberOfSections(in tableView: UITableView) -> Int {
  68. return communityCircleCommentListModel?.reply?.isEmpty ?? true ? 0 : 1
  69. }
  70. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  71. return communityCircleCommentListModel?.reply?.isEmpty ?? true ? 0 : communityCircleCommentListModel?.reply?.prefix(2).count ?? 0
  72. }
  73. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  74. let cell = CircleCommentListReplyTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  75. cell.communityCircleCommentReplyListModel = communityCircleCommentListModel?.reply?[indexPath.row]
  76. return cell
  77. }
  78. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  79. // if communityCircleCommentListModel?.isDelete == 1 {
  80. // SwiftProgressHUD.shared().showText("该评论已删除,暂时不能评论")
  81. // }else {
  82. let vc = CircleCommentReplyListViewController()
  83. vc.communityCircleCommentListModel = communityCircleCommentListModel
  84. UIViewController.topMost?.navigationController?.pushViewController(vc, animated: true)
  85. // }
  86. }
  87. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  88. let communityCircleCommentReplyListModel = communityCircleCommentListModel?.reply?[indexPath.row]
  89. let contentHeight = 17.0 + (communityCircleCommentReplyListModel?.contentHeight ?? 0.0) + 15.0
  90. let spacingHeight : CGFloat = 10.0 + 8.0 + 7.0
  91. let strHeight = contentHeight + spacingHeight
  92. return strHeight
  93. }
  94. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  95. return 0.000001
  96. }
  97. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  98. return 0.000001
  99. }
  100. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  101. return nil
  102. }
  103. func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  104. return nil
  105. }
  106. }