123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- //
- // XYPersonalContentNormalItemsTableViewCell.m
- // TianYou
- //
- // Created by 翟玉磊 on 2021/7/21.
- //
- #import "XYPersonalContentNormalItemsTableViewCell.h"
- #import "XYPersonalContentNormalItemCollectionViewCell.h"
- #import "XYPersonalCenterListModel.h"
- @interface XYPersonalContentNormalItemsTableViewCell ()<UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
- @property (nonatomic, strong) UICollectionView *collectionView;
- @property (nonatomic, strong) NSMutableArray *dataSource;
- @property (nonatomic, strong) NSIndexPath *indexPath;
- @end
- @implementation XYPersonalContentNormalItemsTableViewCell
- + (instancetype)cellWithTableView:(UITableView *)tableView {
- XYPersonalContentNormalItemsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:XYPersonalContentNormalItemsTableViewCell.className];
- if (cell == nil) {
- cell = [[XYPersonalContentNormalItemsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:XYPersonalContentNormalItemsTableViewCell.className];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- return cell;
- }
- - (void)configureModel:(XYPersonalCenterListModel *)model {
- self.dataSource = [NSMutableArray arrayWithArray:model.urlItemArray];
-
- [self.collectionView reloadData];
- }
- - (void)setIndexPath:(NSIndexPath *)indexPath rowsInSection:(NSInteger)rows {
- self.indexPath = indexPath;
- }
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
-
- [self setupUI];
- }
- return self;
- }
- - (void)setupUI {
-
- self.contentView.backgroundColor = Color_White;
-
- [self.contentView addSubview:self.collectionView];
-
- [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self.contentView);
- make.top.equalTo(self.contentView).offset(8.0f);
- make.bottom.equalTo(self.contentView).offset(-8.0f);
- }];
- }
- #pragma mark — UICollectionViewDelegateFlowLayout, UICollectionViewDataSource
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.dataSource.count;
- }
- // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- XYPersonalContentNormalItemCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:XYPersonalContentNormalItemCollectionViewCell.className forIndexPath:indexPath];
- [cell configureModel:self.dataSource[indexPath.row]];
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- [collectionView deselectItemAtIndexPath:indexPath animated:YES];
- if (self.delegate && [self.delegate respondsToSelector:@selector(normalItemsSelectedWithListIndexPath:itemIndexPath:)]) {
- [self.delegate normalItemsSelectedWithListIndexPath:self.indexPath itemIndexPath:indexPath];
- }
- }
- /**
- #import "XYPersonalCenterHeaderEditAlertView.h"
- */
- #pragma mark — Getter
- - (UICollectionView *)collectionView {
- if (!_collectionView) {
- UICollectionViewFlowLayout *flowLayout = [UICollectionViewFlowLayout new];
- flowLayout.itemSize = CGSizeMake(/*67.0f*/(kScreenWidth-30)/4.0, 64.0f);
- flowLayout.minimumLineSpacing = 2.0f;
- flowLayout.minimumInteritemSpacing = 0.0f;
- _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
- _collectionView.delegate = self;
- _collectionView.dataSource = self;
- _collectionView.backgroundColor = Color_Clear;
- _collectionView.scrollEnabled = NO;
- [_collectionView registerCell:XYPersonalContentNormalItemCollectionViewCell.className];
- }
- return _collectionView;
- }
- @end
|