@@ -5,93 +5,107 @@
// Created by Mac on 2025 / 11 / 6.
//
@ import UIKit ;
# import "HomeRankContentVC.h"
# import "HomeHotCell.h"
@ interface HomeRankContentVC ( ) < UITableViewDataSource , UITableViewDelegate >
@ property ( nonatomic , strong ) NSArray < NSDictionary * > * dataSource ; // 简 单 模 拟 数 据
// 自 定 义 卡 片 Cell
# import "HomeRankCardCell.h"
@ interface HomeRankContentVC ( )
@ property ( nonatomic , strong ) NSArray < NSDictionary * > * dataSource ; // 简 单 模 拟 数 据
@ end
@ implementation HomeRankContentVC
- ( void ) viewDidLoad {
[ super viewDidLoad ] ;
// Do any additional setup after loading the view .
// 构 建 数 据 ( 演 示 )
self . dataSource = @ [
@ { @ "rank" : @ 4 , @ "title" : @ "Ambiguous" , @ "sub" : @ "Be Neither Too Close Nor Too Distant, Want To ..." , @ "joined" : @ NO } ,
@ { @ "rank" : @ 5 , @ "title" : @ "Ambiguous" , @ "sub" : @ "Be Neither Too Close Nor Too Distant, Want To ..." , @ "joined" : @ YES } ,
@ { @ "rank" : @ 6 , @ "title" : @ "Ambiguous" , @ "sub" : @ "Be Neither Too Close Nor Too Distant, Want To ..." , @ "joined" : @ NO } ,
@ { @ "rank" : @ 7 , @ "title" : @ "Ambiguous" , @ "sub" : @ "Be Neither Too Close Nor Too Distant, Want To ..." , @ "joined" : @ NO } ,
@ { @ "rank" : @ 4 , @ "title" : @ "Ambiguous" , @ "sub" : @ "Be Neither Too Close Nor Too Distant, Want To ..." , @ "joined" : @ NO } ,
@ { @ "rank" : @ 5 , @ "title" : @ "Ambiguous" , @ "sub" : @ "Be Neither Too Close Nor Too Distant, Want To ..." , @ "joined" : @ YES } ,
@ { @ "rank" : @ 6 , @ "title" : @ "Ambiguous" , @ "sub" : @ "Be Neither Too Close Nor Too Distant, Want To ..." , @ "joined" : @ NO } ,
@ { @ "rank" : @ 7 , @ "title" : @ "Ambiguous" , @ "sub" : @ "Be Neither Too Close Nor Too Distant, Want To ..." , @ "joined" : @ NO } ,
@ { @ "rank" : @ 4 , @ "title" : @ "Ambiguous" , @ "sub" : @ "Be Neither Too Close Nor Too Distant, Want To ..." , @ "joined" : @ NO } ,
@ { @ "rank" : @ 5 , @ "title" : @ "Ambiguous" , @ "sub" : @ "Be Neither Too Close Nor Too Distant, Want To ..." , @ "joined" : @ YES } ,
@ { @ "rank" : @ 6 , @ "title" : @ "Ambiguous" , @ "sub" : @ "Be Neither Too Close Nor Too Distant, Want To ..." , @ "joined" : @ NO } ,
@ { @ "rank" : @ 7 , @ "title" : @ "Ambiguous" , @ "sub" : @ "Be Neither Too Close Nor Too Distant, Want To ..." , @ "joined" : @ NO }
] ;
// 设 置 背 景 颜 色 : 随 机 色
self . view . backgroundColor = COLOR_WITH _RGB ( arc4random ( ) % 255 / 255.0 , arc4random ( ) % 255 / 255.0 , arc4random ( ) % 255 / 255.0 , 1 ) ;
[ self . view addSubview : self . tableView ] ;
[ self . tableView mas_makeConstraints : ^ ( MASConstraintMaker * make ) {
make . left . top . right . equalTo ( self . view ) ;
make . bottom . equalTo ( self . view ) ;
self . view . backgroundColor = COLOR_WITH _RGB ( 246 / 255.0 , 253 / 255.0 , 249 / 255.0 , 1.0 ) ; // 淡 绿 色 背 景
// 数 据
self . dataSource = @ [
@ { @ "title" : @ "High EQ" , @ "desc" : @ "Be Neither Too Close\nNor Too Distant..." , @ "people" : @ "Two Million People\nHave Used It" , @ "added" : @ ( NO ) } ,
@ { @ "title" : @ "High EQ" , @ "desc" : @ "Be Neither Too Close\nNor Too Distant..." , @ "people" : @ "Two Million People\nHave Used It" , @ "added" : @ ( YES ) } ,
@ { @ "title" : @ "High EQ" , @ "desc" : @ "Be Neither Too Close\nNor Too Distant..." , @ "people" : @ "Two Million People\nHave Used It" , @ "added" : @ ( NO ) } ,
@ { @ "title" : @ "High EQ" , @ "desc" : @ "Be Neither Too Close\nNor Too Distant..." , @ "people" : @ "Two Million People\nHave Used It" , @ "added" : @ ( YES ) } ,
@ { @ "title" : @ "High EQ" , @ "desc" : @ "Be Neither Too Close\nNor Too Distant..." , @ "people" : @ "Two Million People\nHave Used It" , @ "added" : @ ( NO ) } ,
@ { @ "title" : @ "High EQ" , @ "desc" : @ "Be Neither Too Close\nNor Too Distant..." , @ "people" : @ "Two Million People\nHave Used It" , @ "added" : @ ( YES ) } ,
@ { @ "title" : @ "High EQ" , @ "desc" : @ "Be Neither Too Close\nNor Too Distant..." , @ "people" : @ "Two Million People\nHave Used It" , @ "added" : @ ( NO ) } ,
@ { @ "title" : @ "High EQ" , @ "desc" : @ "Be Neither Too Close\nNor Too Distant..." , @ "people" : @ "Two Million People\nHave Used It" , @ "added" : @ ( YES ) }
] ;
[ self . view addSubview : self . collectionView ] ;
[ self . collectionView mas_makeConstraints : ^ ( MASConstraintMaker * make ) {
make . edges . equalTo ( self . view ) ;
} ] ;
}
# pragma mark - UITableViewDataSource
- ( UICollectionView * ) collectionView {
if ( ! _collectionView ) {
UICollectionViewFlowLayout * layout = [ [ UICollectionViewFlowLayout alloc ] init ] ;
layout . sectionInset = UIEdgeInsetsMake ( 16 , 16 , 16 , 16 ) ;
layout . minimumLineSpacing = 24 ;
layout . minimumInteritemSpacing = 16 ;
- ( NSInteger ) tableView : ( UITableView * ) tableView numberOfRowsInSection : ( NSInteger ) section {
_collectionView = [ [ UICollectionView alloc ] initWithFrame : CGRectZero collectionViewLayout : layout ] ;
_collectionView . backgroundColor = [ UIColor clearColor ] ;
// _collectionView . alwaysBounceVertical = YES ;
_collectionView . bounces = false ;
_collectionView . dataSource = self ;
_collectionView . delegate = self ;
[ _collectionView registerClass : [ HomeRankCardCell class ] forCellWithReuseIdentifier : @ "HomeRankCardCell" ] ;
// self . collectionView . translatesAutoresizingMaskIntoConstraints = NO ;
}
return _collectionView ;
}
# pragma mark - UICollectionViewDataSource
- ( NSInteger ) collectionView : ( UICollectionView * ) collectionView numberOfItemsInSection : ( NSInteger ) section {
return self . dataSource . count ;
}
- ( UITable ViewCell * ) table View: ( UITable View * ) table View cellForRow AtIndexPath : ( NSIndexPath * ) indexPath {
HomeHot Cell * cell = [ table View dequeueReusableCellWithIdentifier : HomeHotCell . reuseId forIndexPath : indexPath ] ;
NSDictionary * item = self . dataSource [ indexPath . row ] ;
// 配 置 cell
[ cell configWithRank : [ item [ @ "rank" ] integerValue ]
title : item [ @ "title " ]
subtit le : item [ @ "sub " ]
joined : [ item [ @ "joined" ] boolValue ] ] ;
- ( __kindof UICollection ViewCell * ) collection View: ( UICollection View * ) collection View cellForItem AtIndexPath : ( NSIndexPath * ) indexPath {
HomeRankCard Cell * cell = [ collection View dequeueReusableCellWithReuse Identifier : @ "HomeRankCardCell" forIndexPath : indexPath ] ;
NSDictionary * d = self . dataSource [ indexPath . item ] ;
BOOL added = [ d [ @ "added" ] boolValue ] ;
[ cell configure WithTitle : d [ @ "title" ]
desc : d [ @ "desc " ]
peop le : d [ @ "people " ]
added : added ] ;
__weak typeof ( self ) weakSelf = self ;
cell . onTapAction = ^ {
// 切 换 添 加 / 已 添 加 状 态 并 刷 新 该 项
NSMutableArray * m = [ weakSelf . dataSource mutableCopy ] ;
NSMutableDictionary * md = [ m [ indexPath . item ] mutableCopy ] ;
BOOL cur = [ md [ @ "added" ] boolValue ] ;
md [ @ "added" ] = @ ( ! cur ) ;
m [ indexPath . item ] = md ;
weakSelf . dataSource = [ m copy ] ;
[ weakSelf . collectionView reloadItemsAtIndexPaths : @ [ indexPath ] ] ;
} ;
return cell ;
}
# pragma mark - UITable ViewDelegate
# pragma mark - UICollection ViewDelegateFlowLayout
- ( CGFloat ) table View : ( UITable View * ) tableView heightForRow AtIndexPath: ( NSIndexPath * ) indexPath {
return 84.0 ;
}
- ( void ) tableView : ( UITableView * ) tableView didSelectRowAtIndexPath : ( NSIndexPath * ) indexPath {
[ tableView deselectRowAtIndexPath : indexPath animated : YES ] ;
}
- ( BaseTableView * ) tableView {
if ( ! _tableView ) {
// 使 用 BaseTableView , 统 一 默 认 配 置
_tableView = [ [ BaseTableView alloc ] initWithFrame : CGRectZero style : UITableViewStylePlain ] ;
_tableView . dataSource = self ;
_tableView . delegate = self ;
_tableView . bounces = false ;
_tableView . separatorStyle = UITableViewCellSeparatorStyleNone ; // 设 计 为 卡 片 式 , 去 掉 系 统 分 割 线
_tableView . showsVerticalScrollIndicator = NO ;
_tableView . contentInset = UIEdgeInsetsMake ( 8 , 0 , KB_SafeAreaBottom ( ) , 0 ) ;
[ _tableView registerClass : HomeHotCell . class forCellReuseIdentifier : HomeHotCell . reuseId ] ;
}
return _tableView ;
- ( CGSize ) collection View : ( UICollection View * ) collectionView layout : ( UICollectionViewLayout * ) collectionViewLayout sizeForItem AtIndexPath: ( NSIndexPath * ) indexPath {
CGFloat totalHInset = 16 + 16 ; // section i / l / r
CGFloat spacing = 16 ; // interitem spacing
CGFloat w = collectionView . bounds . size . width - totalHInset ; // not including section insets yet
// Two columns → each width = ( width - spacing - lr insets ) / 2
CGFloat cellWidth = ( w - spacing ) / 2.0 ;
// 固 定 高 度 , 接 近 示 意 图 比 例
CGFloat cellHeight = 340.0 ;
return CGSizeMake ( floor ( cellWidth ) , cellHeight ) ;
}
# pragma mark - JXCategoryListContentViewDelegate
/ * *
实 现 < JXCategoryListContentViewDelegate > 协 议 方 法 , 返 回 该 视 图 控 制 器 所 拥 有 的 「 视 图 」
* /
- ( UIView * ) listView {
return self . view ;
}
@ end