Files
peko-ios/YuMi/Modules/YMNewHome/View/Cell/XPNewHomePlayTableViewCell.m
2023-10-08 16:46:12 +08:00

104 lines
3.6 KiB
Objective-C

//
// XPNewHomePlayTableViewCell.m
// YuMi
//
// Created by YuMi on 2022/10/8.
//
#import "XPNewHomePlayTableViewCell.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "DJDKMIMOMColor.h"
#import "NetImageView.h"
#import "NSArray+Safe.h"
///View
#import "XPNewHomePlayItemCollectionViewCell.h"
@interface XPNewHomePlayTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic,strong) UICollectionView *collectionView;
@end
@implementation XPNewHomePlayTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
-(void)chooseGameAction{
if(self.delegate && [self.delegate respondsToSelector:@selector(chooseGameAction)]){
[self.delegate chooseGameAction];
}
}
#pragma mark - Private Method
- (void)initSubViews {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.collectionView];
}
- (void)initSubViewConstraints {
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.top.trailing.equalTo(self.contentView);
make.height.mas_equalTo(kGetScaleWidth(92));
}];
}
-(void)setPlayRoomList:(NSArray *)playRoomList{
_playRoomList = playRoomList;
[self.collectionView reloadData];
}
#pragma mark - UICollectionViewDelegate, UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.playRoomList.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
XPNewHomePlayItemCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPNewHomePlayItemCollectionViewCell class]) forIndexPath:indexPath];
cell.roomInfo = [self.playRoomList safeObjectAtIndex1:indexPath.row];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
if (self.playRoomList.count > 0) {
HomePlayRoomModel * roomInfo = [self.playRoomList safeObjectAtIndex1:indexPath.row];
if (self.delegate && [self.delegate respondsToSelector:@selector(xPNewHomePlayTableViewCell:didSelectItem:)]) {
[self.delegate xPNewHomePlayTableViewCell:self didSelectItem:roomInfo];
}
}
}
#pragma mark - Getters And Setters
- (UICollectionView *)collectionView{
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(kGetScaleWidth(100), kGetScaleWidth(92));
layout.sectionInset = UIEdgeInsetsMake(0, kGetScaleWidth(12), 0, kGetScaleWidth(12));
layout.minimumLineSpacing = kGetScaleWidth(8);
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.tag = 9000002;
_collectionView.backgroundColor = [UIColor clearColor];
_collectionView.showsVerticalScrollIndicator = NO;
_collectionView.showsHorizontalScrollIndicator = NO;
[_collectionView registerClass:[XPNewHomePlayItemCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPNewHomePlayItemCollectionViewCell class])];
}
return _collectionView;
}
@end