// // NYBlockExerciseViewController.m // jiaPei // // Created by Ning.ge on 2024/12/5. // Copyright © 2024 JCZ. All rights reserved. // #import "NYBlockExerciseViewController.h" @interface NYBlockExerciseViewController () /// viewModel @property (nonatomic, readonly, strong) NYBlockExerciseViewModel *viewModel; @end @implementation NYBlockExerciseViewController @dynamic viewModel; #pragma mark - SystemMethod - (void)viewDidLoad { [super viewDidLoad]; /// 初始化 [self rq_setup]; } - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; self.view.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT); } #pragma mark - PrivateMethods /// 初始化 - (void)rq_setup { /// set up ... self.collectionView.bounces = NO; self.collectionView.backgroundColor = UIColor.clearColor; } #pragma mark - OverrideMethods /// 配置collectionView的区域 - (UIEdgeInsets)contentInset { return UIEdgeInsetsMake(RQ_APPLICATION_STATUS_BAR_HEIGHT + RQ_APPLICATION_NAV_BAR_HEIGHT, 0, 0, 0); } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath { RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section]; RQCommonCollectionItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row]; UICollectionViewCell *cell = [NSClassFromString(itemViewModel.itemClassName) cellWithCollectionView:collectionView forIndexPath:indexPath]; return cell; } - (void)configureCell:(RQCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object { [cell bindViewModel:object]; } - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { return UIEdgeInsetsMake(0, 16, 0, 16); } - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { @weakify(self) RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section]; // 如果是头视图 if (kind == UICollectionElementKindSectionHeader) { if ([groupViewModel isKindOfClass:[NYBlockExerciseGroupViewModel class]]) { NYBlockExerciseHeaderView *headerView = [NYBlockExerciseHeaderView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath]; RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section]; [headerView bindViewModel:groupViewModel]; headerView.headerContentLabel.hidden = YES; headerView.footerContentLabel.hidden = YES; return headerView; } } RQCommonReusableView *headerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath]; [headerView bindViewModel:groupViewModel]; headerView.headerContentLabel.hidden = YES; headerView.footerContentLabel.hidden = YES; return headerView; } @end