From 642175113bf6f2c90894e689dacda50278cad570 Mon Sep 17 00:00:00 2001 From: 杨锴 <841720330@qq.com> Date: 星期四, 19 九月 2024 15:50:11 +0800 Subject: [PATCH] complete most UI & Mock API --- XQMuse/Root/Me/VC/StudyListVC.swift | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 52 insertions(+), 7 deletions(-) diff --git a/XQMuse/Root/Me/VC/StudyListVC.swift b/XQMuse/Root/Me/VC/StudyListVC.swift index d1fb958..464fb98 100644 --- a/XQMuse/Root/Me/VC/StudyListVC.swift +++ b/XQMuse/Root/Me/VC/StudyListVC.swift @@ -12,14 +12,29 @@ class StudyListVC: BaseVC { @IBOutlet weak var collectionView: UICollectionView! + + private var datas:MyStudyModel? override func viewDidLoad() { super.viewDidLoad() title = "学习" + + Services.studyPage().subscribe(onNext: {data in + self.datas = data.data + self.collectionView.reloadData() + }).disposed(by: disposeBag) } override func setUI() { super.setUI() view.backgroundColor = UIColor(hexString: "#F6F6F6") + + + let layout = HoverHeaderFlowLayout() + layout.naviHeight = 0 + let w = (JQ_ScreenW - 18 * 3) / 2 + layout.itemSize = CGSize(width: w, height: w * 1.319) + layout.headerReferenceSize = CGSize(width: JQ_ScreenW, height: 59) + collectionView.collectionViewLayout = layout collectionView.delegate = self collectionView.dataSource = self collectionView.backgroundColor = UIColor(hexString: "#F6F6F6") @@ -37,25 +52,52 @@ extension StudyListVC:UICollectionViewDelegate & UICollectionViewDataSource{ + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + + var modelId:Int? + if indexPath.section == 0{ + modelId = datas?.courseList[indexPath.row].id + } + + if indexPath.section == 0{ + modelId = datas?.freeCourseList[indexPath.row].id + } + + if let id = modelId{ + let vc = CourseDetialVC(courseId: id) + push(vc: vc) + } + } + func numberOfSections(in collectionView: UICollectionView) -> Int { return 2 } + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { if indexPath.section == 0{ - let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_EmptyCCell", for: indexPath) as! EmptyCCell + let count = datas?.courseList.count ?? 0 + if count == 0{ + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_EmptyCCell", for: indexPath) as! EmptyCCell + return cell + }else{ + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_1_CCell", for: indexPath) as! HomeRelaxBanner_2_1_CCell + cell.setCourseModel(datas!.courseList[indexPath.row]) + return cell + } + }else{ + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_1_CCell", for: indexPath) as! HomeRelaxBanner_2_1_CCell + cell.setCourseModel(datas!.freeCourseList[indexPath.row]) return cell } - - let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_1_CCell", for: indexPath) as! HomeRelaxBanner_2_1_CCell - cell.backgroundColor = .jq_randomColor - return cell } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { if section == 0{ + let count = datas?.courseList.count ?? 0 + if count > 0{return count} return 1 }else { - return 5 + return datas?.freeCourseList.count ?? 0 } } } @@ -88,7 +130,10 @@ } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { - if indexPath.section == 0{ + + let count = datas?.courseList.count ?? 0 + + if indexPath.section == 0 && count == 0{ return CGSize(width: JQ_ScreenW, height: 279) } -- Gitblit v1.7.1