Files
yuyin_ios/SweetParty/主类/狸猫新增/Sud小游戏/YYRoomGamePickView.m
2025-08-08 11:05:33 +08:00

85 lines
2.5 KiB
Objective-C
Executable File

//
// YYRoomGamePickView.m
// YaYin
//
// Created by bj_szd on 2023/2/21.
// Copyright © 2023 YaYin. All rights reserved.
//
#import "YYRoomGamePickView.h"
#import "YYRoomGamePickCell.h"
@interface YYRoomGamePickView () <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
@property (nonatomic, strong) NSArray *dataArray;
@end
@implementation YYRoomGamePickView
- (void)awakeFromNib {
[super awakeFromNib];
[self createUI];
[self fetchData];
}
- (void)createUI {
WEAK_SELF
[self.touchImgV dg_Tapped:^{
[weakSelf onBack:nil];
}];
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(55, 95);
layout.minimumInteritemSpacing = 30;
layout.minimumLineSpacing = 10;
layout.sectionInset = UIEdgeInsetsMake(0, 26, 0, 26);
_collectionView.collectionViewLayout = layout;
_collectionView.delegate = self;
_collectionView.dataSource = self;
[_collectionView registerNib:[UINib nibWithNibName:@"YYRoomGamePickCell" bundle:nil] forCellWithReuseIdentifier:@"YYRoomGamePickCell"];
}
- (void)fetchData {
NSString *jsonPath = [[NSBundle mainBundle] pathForResource:@"sud_game" ofType:@"json"];
NSString *jsonStr = [NSString stringWithContentsOfFile:jsonPath encoding:NSUTF8StringEncoding error:nil];
NSArray *arrGame = [YYRoomGamePickModel mj_objectArrayWithKeyValuesArray:jsonStr];
self.dataArray = arrGame;
[self.collectionView reloadData];
}
- (IBAction)onBack:(id)sender {
[self removeFromSuperview];
}
#pragma mark -------- collectionView代理方法 ------
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.dataArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
YYRoomGamePickCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YYRoomGamePickCell" forIndexPath:indexPath];
YYRoomGamePickModel *model = self.dataArray[indexPath.row];
cell.model = model;
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
YYRoomGamePickModel *model = self.dataArray[indexPath.row];
if (self.onPickGameBlock) {
self.onPickGameBlock(model.gameId);
}
[self onBack:nil];
}
@end