Files
yinmeng-ios/xplan-ios/Main/Home/View/Cell/XPHomeAttentionTableViewCell.m
2022-11-11 17:46:37 +08:00

88 lines
3.1 KiB
Objective-C

//
// XPHomeAttentionTableViewCell.m
// xplan-ios
//
// Created by 冯硕 on 2022/3/2.
//
#import "XPHomeAttentionTableViewCell.h"
///Third
#import <Masonry/Masonry.h>
#import "NSArray+Safe.h"
///View
#import "XPHomeAttentionCollectionViewCell.h"
@interface XPHomeAttentionTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
///列表
@property (nonatomic,strong) UICollectionView *collectionView;
@end
@implementation XPHomeAttentionTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
self.backgroundColor = [UIColor clearColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.contentView addSubview:self.collectionView];
}
- (void)initSubViewConstraints {
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.contentView);
}];
}
#pragma mark - UICollectionViewCellDelegate And UICollectionViewDatasource
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
XPHomeAttentionCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPHomeAttentionCollectionViewCell class]) forIndexPath:indexPath];
cell.liveRoom = [self.attentionList safeObjectAtIndex1:indexPath.item];
return cell;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.attentionList.count;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
if (self.attentionList.count > 0) {
HomeLiveRoomModel * liveModel = [self.attentionList safeObjectAtIndex1:indexPath.item];
if (self.delegate && [self.delegate respondsToSelector:@selector(xPHomeAttentionTableViewCell:didClickItem:)]) {
[self.delegate xPHomeAttentionTableViewCell:self didClickItem:liveModel];
}
}
}
#pragma mark - Getters And Setters
- (void)setAttentionList:(NSArray *)attentionList {
_attentionList = attentionList;
[self.collectionView reloadData];
}
- (UICollectionView *)collectionView{
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.minimumLineSpacing = 8;
layout.itemSize = CGSizeMake(56, 56+ 24);
layout.sectionInset = UIEdgeInsetsMake(12, 15, 12, 15);
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.backgroundColor = [UIColor clearColor];
[_collectionView registerClass:[XPHomeAttentionCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPHomeAttentionCollectionViewCell class])];
}
return _collectionView;
}
@end