// // CommunityRecommendController.swift // RainbowPlanet // // Created by Christopher on 2019/6/13. // Copyright © 2019 RainbowPlanet. All rights reserved. // import UIKit class CommunityRecommendController: BaseViewController { override func viewDidLoad() { super.viewDidLoad() setupViews() setupLayouts() } override func setupViews() { navigationBar.title = "推荐详情" view.backgroundColor = kf7f8faColor view.addSubview(commentView) view.addSubview(tableView) } override func setupLayouts() { commentView.snp.makeConstraints { (make) in make.left.right.equalToSuperview() make.height.equalTo(48) make.bottom.equalToSuperview().offset(-kSafeTabBarHeight) } tableView.snp.makeConstraints { (make) in make.top.equalToSuperview().offset(kNavBarTotalHeight) make.left.right.equalToSuperview() make.bottom.equalTo(commentView.snp_top).offset(0) } } override func setupData() { } lazy var tableView: UITableView = { let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped) tableView.separatorStyle = .none tableView.backgroundColor = kf7f8faColor tableView.dataSource = self tableView.delegate = self tableView.estimatedRowHeight = 200 tableView.estimatedSectionFooterHeight = 0.000001 tableView.estimatedSectionHeaderHeight = 0.000001 return tableView }() lazy var commentView: RecommendBottomCommentView = { let commentView = RecommendBottomCommentView() commentView.bottomClickClosure = { [weak self] (clickType) in switch clickType { case BottomClickType.typeComment: print("添加评论") case BottomClickType.typeLike: print("添加喜欢") case BottomClickType.typeCollect: print("添加收藏") default: print("添加收藏") } } return commentView }() } // MARK: - tableView dataSource && delegate extension CommunityRecommendController: UITableViewDataSource, UITableViewDelegate { func numberOfSections(in tableView: UITableView) -> Int { return 5 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { switch section { case 0: return 1 case 1: return 1 case 2: return 1 case 3: return 3 default: return 1 } } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { switch indexPath.section { case 0: let cell = RecommendDetailContentCell.cellWith(tableView: tableView, indexPath: indexPath) cell.layoutIfNeeded() cell.reloadData() return cell case 1: let cell = RecommendNoneCommentCell.cellWith(tableView: tableView, indexPath: indexPath) return cell case 2: let cell = RecommendDefaultBackCell.cellWith(tableView: tableView, indexPath: indexPath) cell.jumpClosure = { [weak self] in print("跳转至首页") } return cell case 3: let cell = CommunityMajorCommentCell.cellWith(tableView: tableView, indexPath: indexPath) return cell case 4: let cell = RecommendSimilarCell.cellWith(tableView: tableView, indexPath: indexPath) cell.layoutIfNeeded() cell.reloadData() return cell default: return UITableViewCell() } } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { print("点击了----\(indexPath.row)") } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { // testt if indexPath.section == 2 { return 312 } return UITableView.automaticDimension } func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { if section == 3 { return 64 } else { return 10 } } func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { if section == 3 { return 51 } else { return 0 } } func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { if section == 3 { let headerView = RecommendCommentHeader(frame: CGRect.zero) return headerView } else { return nil } } func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { if section == 3 { let footerView = RecommendCommentFooter(frame: CGRect.zero) footerView.unfoldClosure = { [weak self] in print("----点击了展开") } return footerView } else { return nil } } }