提交
This commit is contained in:
117
QXLive/HomePage(声播)/Controlller/QXHomeSubViewController.m
Normal file
117
QXLive/HomePage(声播)/Controlller/QXHomeSubViewController.m
Normal file
@@ -0,0 +1,117 @@
|
||||
//
|
||||
// QXHomeSubViewController.m
|
||||
// QXLive
|
||||
//
|
||||
// Created by 启星 on 2025/5/7.
|
||||
//
|
||||
|
||||
#import "QXHomeSubViewController.h"
|
||||
#import "QXHomeRoomCell.h"
|
||||
#import "QXHomePageNetwork.h"
|
||||
|
||||
@interface QXHomeSubViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
|
||||
@property (nonatomic,strong)UICollectionView *collectionView;
|
||||
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
|
||||
@end
|
||||
|
||||
@implementation QXHomeSubViewController
|
||||
-(UIView *)listView{
|
||||
return self.view;
|
||||
}
|
||||
-(void)listWillAppear{
|
||||
[self getRoomList];
|
||||
}
|
||||
-(UIScrollView *)listScrollView{
|
||||
return self.collectionView;
|
||||
}
|
||||
- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
|
||||
self.scrollCallback = callback;
|
||||
}
|
||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
||||
if (self.scrollCallback != nil) {
|
||||
self.scrollCallback(scrollView);
|
||||
}
|
||||
}
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view.
|
||||
|
||||
}
|
||||
-(void)initSubViews{
|
||||
self.page = 1;
|
||||
[self.view addSubview:self.collectionView];
|
||||
// [self getRoomList];
|
||||
self.bgImageHidden = YES;
|
||||
}
|
||||
-(void)viewDidAppear:(BOOL)animated{
|
||||
[super viewDidAppear:animated];
|
||||
[self.collectionView reloadData];
|
||||
}
|
||||
-(void)setRoomType:(QXMyRoomType *)roomType{
|
||||
_roomType = roomType;
|
||||
[self getRoomList];
|
||||
}
|
||||
- (void)getRoomList {
|
||||
__weak typeof(self)weakSelf = self;
|
||||
[QXHomePageNetwork homeRoomListWithPage:self.page is_top:NO label_id:self.roomType.id successBlock:^(NSArray<QXRoomListModel *> * _Nonnull list, BOOL isAppStore) {
|
||||
if (self.page == 1) {
|
||||
[weakSelf.dataArray removeAllObjects];
|
||||
}
|
||||
[weakSelf.dataArray addObjectsFromArray:list];
|
||||
[self.collectionView reloadData];
|
||||
if (list.count == 0) {
|
||||
self.collectionView.mj_footer.state = MJRefreshStateNoMoreData;
|
||||
}else{
|
||||
[self.collectionView.mj_footer endRefreshing];
|
||||
}
|
||||
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
||||
[self.collectionView.mj_footer endRefreshing];
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout
|
||||
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
|
||||
return 1;
|
||||
}
|
||||
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
||||
return self.dataArray.count;
|
||||
}
|
||||
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
||||
QXHomeRoomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXHomeRoomCell" forIndexPath:indexPath];
|
||||
cell.model = self.dataArray[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{
|
||||
QXRoomListModel *model = self.dataArray[indexPath.row];
|
||||
[[QXGlobal shareGlobal] joinRoomWithRoomId:model.room_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, 0, 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"];
|
||||
MJWeakSelf
|
||||
_collectionView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
|
||||
weakSelf.page++;
|
||||
[weakSelf getRoomList];
|
||||
}];
|
||||
}
|
||||
return _collectionView;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user