Files
my_yuyin/QXLive/HomePage(声播)/Controlller/QXHomeSearchResultVC.m
2025-09-22 18:48:29 +08:00

88 lines
3.2 KiB
Objective-C

//
// QXHomeSearchResultVC.m
// QXLive
//
// Created by 启星 on 2025/7/10.
//
#import "QXHomeSearchResultVC.h"
#import "QXHomeRoomCell.h"
@interface QXHomeSearchResultVC ()<UICollectionViewDelegate,UICollectionViewDataSource>
@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)setResultArray:(NSArray *)resultArray{
_resultArray = resultArray;
[self.collectionView reloadData];
}
#pragma mark - UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.resultArray.count;
}
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
QXHomeRoomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXHomeRoomCell" forIndexPath:indexPath];
cell.searchModel = self.resultArray[indexPath.row];
return cell;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
return CGSizeMake((SCREEN_WIDTH-15*3-1)/2.0, (SCREEN_WIDTH-15*3-1)/2.0);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
QXSearchModel *model = self.resultArray[indexPath.row];
[[QXGlobal shareGlobal] joinRoomWithRoomId:model.id isRejoin:NO navagationController:self.navigationController];
}
-(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+TabbarContentHeight)) collectionViewLayout:layout];
_collectionView.delegate = self;
_collectionView.dataSource = self;
_collectionView.backgroundColor = [UIColor clearColor];
[_collectionView registerNib:[UINib nibWithNibName:@"QXHomeRoomCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXHomeRoomCell"];
}
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