CommunityRecommendController.swift 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // CommunityRecommendController.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/6/13.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. class CommunityRecommendController: BaseViewController {
  10. override func viewDidLoad() {
  11. super.viewDidLoad()
  12. setupViews()
  13. setupLayouts()
  14. }
  15. override func setupViews() {
  16. navigationBar.title = "推荐详情"
  17. view.backgroundColor = kf7f8faColor
  18. view.addSubview(commentView)
  19. view.addSubview(tableView)
  20. }
  21. override func setupLayouts() {
  22. commentView.snp.makeConstraints { (make) in
  23. make.left.right.equalToSuperview()
  24. make.height.equalTo(48)
  25. make.bottom.equalToSuperview().offset(-kSafeTabBarHeight)
  26. }
  27. tableView.snp.makeConstraints { (make) in
  28. make.top.equalToSuperview().offset(kNavBarTotalHeight)
  29. make.left.right.equalToSuperview()
  30. make.bottom.equalTo(commentView.snp_top).offset(0)
  31. }
  32. }
  33. override func setupData() {
  34. }
  35. lazy var tableView: UITableView = {
  36. let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
  37. tableView.separatorStyle = .none
  38. tableView.backgroundColor = kf7f8faColor
  39. tableView.dataSource = self
  40. tableView.delegate = self
  41. tableView.estimatedRowHeight = 200
  42. tableView.estimatedSectionFooterHeight = 0.000001
  43. tableView.estimatedSectionHeaderHeight = 0.000001
  44. return tableView
  45. }()
  46. lazy var commentView: RecommendBottomCommentView = {
  47. let commentView = RecommendBottomCommentView()
  48. commentView.bottomClickClosure = {
  49. [weak self] (clickType) in
  50. switch clickType {
  51. case BottomClickType.typeComment:
  52. print("添加评论")
  53. case BottomClickType.typeLike:
  54. print("添加喜欢")
  55. case BottomClickType.typeCollect:
  56. print("添加收藏")
  57. default:
  58. print("添加收藏")
  59. }
  60. }
  61. return commentView
  62. }()
  63. }
  64. // MARK: - tableView dataSource && delegate
  65. extension CommunityRecommendController: UITableViewDataSource, UITableViewDelegate {
  66. func numberOfSections(in tableView: UITableView) -> Int {
  67. return 5
  68. }
  69. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  70. switch section {
  71. case 0:
  72. return 1
  73. case 1:
  74. return 1
  75. case 2:
  76. return 1
  77. case 3:
  78. return 3
  79. default:
  80. return 1
  81. }
  82. }
  83. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  84. switch indexPath.section {
  85. case 0:
  86. let cell = RecommendDetailContentCell.cellWith(tableView: tableView, indexPath: indexPath)
  87. cell.layoutIfNeeded()
  88. cell.reloadData()
  89. return cell
  90. case 1:
  91. let cell = RecommendNoneCommentCell.cellWith(tableView: tableView, indexPath: indexPath)
  92. return cell
  93. case 2:
  94. let cell = RecommendDefaultBackCell.cellWith(tableView: tableView, indexPath: indexPath)
  95. cell.jumpClosure = {
  96. [weak self] in
  97. print("跳转至首页")
  98. }
  99. return cell
  100. case 3:
  101. let cell = CommunityMajorCommentCell.cellWith(tableView: tableView, indexPath: indexPath)
  102. return cell
  103. case 4:
  104. let cell = RecommendSimilarCell.cellWith(tableView: tableView, indexPath: indexPath)
  105. cell.layoutIfNeeded()
  106. cell.reloadData()
  107. return cell
  108. default:
  109. return UITableViewCell()
  110. }
  111. }
  112. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  113. print("点击了----\(indexPath.row)")
  114. }
  115. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  116. // testt
  117. if indexPath.section == 2 {
  118. return 312
  119. }
  120. return UITableView.automaticDimension
  121. }
  122. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  123. if section == 3 {
  124. return 64
  125. } else {
  126. return 10
  127. }
  128. }
  129. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  130. if section == 3 {
  131. return 51
  132. } else {
  133. return 0
  134. }
  135. }
  136. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  137. if section == 3 {
  138. let headerView = RecommendCommentHeader(frame: CGRect.zero)
  139. return headerView
  140. } else {
  141. return nil
  142. }
  143. }
  144. func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  145. if section == 3 {
  146. let footerView = RecommendCommentFooter(frame: CGRect.zero)
  147. footerView.unfoldClosure = {
  148. [weak self] in
  149. print("----点击了展开")
  150. }
  151. return footerView
  152. } else {
  153. return nil
  154. }
  155. }
  156. }