// // QXHomeSearchResultVC.m // QXLive // // Created by 启星 on 2025/7/10. // #import "QXHomeSearchResultVC.h" #import "QXHomeRoomCell.h" #import "QXSearchHeaderReusableView.h" #import "QXSearchUserCell.h" #import "QXUserHomePageViewController.h" @interface QXHomeSearchResultVC () @property (nonatomic,strong)UICollectionView *collectionView; @end @implementation QXHomeSearchResultVC - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } -(void)setNavgationItems{ [super setNavgationItems]; self.navigationItem.title = @"搜索结果"; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:NO animated:YES]; } -(void)initSubViews{ [self.view addSubview:self.collectionView]; } -(void)setModel:(QXSearchListModel *)model{ _model = model; [self.collectionView reloadData]; } #pragma mark - UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 2; } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ if (section == 0) { return self.model.rooms.count; }else{ return self.model.users.count; } } -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 0) { QXHomeRoomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXHomeRoomCell" forIndexPath:indexPath]; cell.model = self.model.rooms[indexPath.row]; return cell; }else{ QXSearchUserCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXSearchUserCell" forIndexPath:indexPath]; cell.model = self.model.users[indexPath.row]; return cell; } } -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 0) { return CGSizeMake((SCREEN_WIDTH-15*3-1)/2.0, (SCREEN_WIDTH-15*3-1)/2.0); }else{ return CGSizeMake(SCREEN_WIDTH, 92); } } - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{ if ([kind isEqualToString:UICollectionElementKindSectionHeader]) { QXSearchHeaderReusableView *reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"QXSearchHeaderReusableView" forIndexPath:indexPath]; if (indexPath.section == 0) { reusableView.title = @"相关房间"; }else{ reusableView.title = @"相关用户"; } return reusableView; }else{ return nil; } } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{ return CGSizeMake(SCREEN_WIDTH, 48); } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{ return CGSizeZero; } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 0) { QXRoomListModel *model = self.model.rooms[indexPath.row]; [[QXGlobal shareGlobal] joinRoomWithRoomId:model.room_id isRejoin:NO navagationController:self.navigationController]; }else{ QXUserHomeModel *model = self.model.users[indexPath.row]; QXUserHomePageViewController *vc = [[QXUserHomePageViewController alloc] init]; vc.user_id = model.user_id; [self.navigationController pushViewController:vc animated:YES]; } } -(UICollectionView *)collectionView{ if (!_collectionView) { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.minimumLineSpacing = 15; layout.minimumInteritemSpacing = 15; layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15); _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 16, SCREEN_WIDTH, SCREEN_HEIGHT-NavContentHeight) collectionViewLayout:layout]; _collectionView.delegate = self; _collectionView.dataSource = self; _collectionView.bounces = YES; _collectionView.backgroundColor = [UIColor clearColor]; [_collectionView registerNib:[UINib nibWithNibName:@"QXHomeRoomCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXHomeRoomCell"]; [_collectionView registerNib:[UINib nibWithNibName:@"QXSearchUserCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXSearchUserCell"]; [_collectionView registerClass:[QXSearchHeaderReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"QXSearchHeaderReusableView"]; } return _collectionView; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end