CommunityMyFollowTopicController.swift 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // CommunityMyFollowTopicController.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/6/12.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. import SwiftyMediator
  10. class CommunityMyFollowTopicController: BaseViewController {
  11. override func didReceiveMemoryWarning() {
  12. super.didReceiveMemoryWarning()
  13. }
  14. var communityMemberFollowTopicListDataModels = Array<CommunityMemberFollowTopicListDataModel>()
  15. override func viewDidLoad() {
  16. super.viewDidLoad()
  17. setupViews()
  18. setupLayouts()
  19. setupData()
  20. }
  21. override func setupViews() {
  22. navigationBar.title = "我的关注话题"
  23. view.backgroundColor = kf7f8faColor
  24. view.addSubview(tableView)
  25. view.insertSubview(navigationBar, aboveSubview: tableView)
  26. }
  27. override func setupLayouts() {
  28. tableView.snp.makeConstraints { (make) in
  29. make.top.equalToSuperview().offset(kNavBarTotalHeight)
  30. make.left.right.bottom.equalTo(0)
  31. }
  32. if #available(iOS 11.0, *) {
  33. tableView.contentInsetAdjustmentBehavior = .never
  34. }
  35. }
  36. override func setupData() {
  37. tableView.addHeader(withBeginRefresh: true, animation: false) {
  38. [weak self] (page) in
  39. self?.communityMemberFollowTopicListApi(page: page)
  40. }
  41. tableView.addAutoNormalFooter(withAutomaticallyRefresh: true, loadMoreBlock: {
  42. [weak self] (page) in
  43. self?.communityMemberFollowTopicListApi(page: page)
  44. })
  45. }
  46. lazy var tableView: UITableView = {
  47. let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
  48. tableView.separatorStyle = .none
  49. tableView.backgroundColor = kf7f8faColor
  50. tableView.dataSource = self
  51. tableView.delegate = self
  52. tableView.rowHeight = 60
  53. return tableView
  54. }()
  55. }
  56. extension CommunityMyFollowTopicController {
  57. //我的关注话题
  58. func communityMemberFollowTopicListApi(page:Int) {
  59. SwiftMoyaNetWorkServiceCommunity.shared().communityMemberFollowTopicListApi(page: page, completion: {
  60. [weak self] (communityMemberFollowTopicListModel) -> (Void) in
  61. DIYEmptyView.emptyNoDataTableView(tableView: self?.tableView, imageStr: .twelve, detailStr: .twelve)
  62. let communityMemberFollowTopicListModel = communityMemberFollowTopicListModel as? CommunityMemberFollowTopicListModel
  63. if communityMemberFollowTopicListModel?.pagination?.currentPage == 1{
  64. self?.communityMemberFollowTopicListDataModels.removeAll()
  65. self?.tableView.resetNoMoreData()
  66. }
  67. self?.communityMemberFollowTopicListDataModels = (self?.communityMemberFollowTopicListDataModels)! + (communityMemberFollowTopicListModel?.data!)!
  68. self?.tableView.reloadData()
  69. MJRefreshManager.mjRefreshManagerPaginationNoHiddenFooter(tableView: self?.tableView, pagination:communityMemberFollowTopicListModel?.pagination)
  70. }) {[weak self] loadingStatus in
  71. MJRefreshManager.mjRefreshManagerLoadingStatus(tableView: self?.tableView,loadingStatus: loadingStatus)
  72. }
  73. }
  74. }
  75. // MARK: - tableView dataSource && delegate
  76. extension CommunityMyFollowTopicController: UITableViewDataSource, UITableViewDelegate {
  77. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  78. return communityMemberFollowTopicListDataModels.isEmpty ? 0 : communityMemberFollowTopicListDataModels.count
  79. }
  80. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  81. let cell = CommunityMyFollowTopicCell.cellWith(tableView: tableView, indexPath: indexPath)
  82. cell.communityMemberFollowTopicListDataModel = communityMemberFollowTopicListDataModels[indexPath.row]
  83. return cell
  84. }
  85. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  86. tableView.deselectRow(at: indexPath, animated: true)
  87. Mediator.push(CommunityRouterModuleType.pushFeaturedTopics(id: communityMemberFollowTopicListDataModels[indexPath.row].topicId ?? 0))
  88. }
  89. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  90. return 60
  91. }
  92. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  93. return 10
  94. }
  95. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  96. return 0
  97. }
  98. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  99. return nil
  100. }
  101. func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  102. return nil
  103. }
  104. }