| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- //
- // CGPTCell.m
- // jitao
- //
- // Created by 罗云飞 on 2018/1/20.
- // Copyright © 2018年 罗云飞. All rights reserved.
- //
- #import "CGPTCell.h"
- #import "CGPTCollectionViewCell.h"
- @implementation CGPTCell{
- UICollectionViewFlowLayout *flowLayout;
- NSMutableArray *dataArray;
- }
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
-
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- dataArray = NewMutableArrayInit;
- [self.contentView addSubview:_CollView = [NewControlPackage collectionViewInitWithFrame:CGRectMake(0.0, 0.6, SCREEN_WIDTH, 240) delegate:self dataSource:self backgroundColor:NewWhiteColor scrollEnabled:YES alwaysBounceVertical:YES alwaysBounceHorizontal:NO showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO collectionViewFlowLayout:flowLayout sectionInset:UIEdgeInsetsMake(0, 0, 0, 0) headerReference:CGSizeMake(0, 0) footerReference:CGSizeMake(0, 0) minimumInteritemSpacing:0 minimumLineSpacing:0 scrollDirection:0 hidden:NO tag:105 userInteractionEnabled:YES]];
- [_CollView registerClass:[CGPTCollectionViewCell class] forCellWithReuseIdentifier:@"CGPTCollViewCell"];
- }
- return self;
- }
- //定义展示的UICollectionViewCell的个数
- -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
- if (dataArray.count == 3) {
- return dataArray.count;
- }else{
- return dataArray.count+1;
- }
- }
- //定义展示的Section的个数
- -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
- {
- return 1;
- }
- //每个UICollectionView展示的内容
- -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- // HomeModel *HModel = [self.HomeArray objectAtIndex:indexPath.row];
- CGPTCollectionViewCell *collcell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CGPTCollViewCell" forIndexPath:indexPath];
- collcell.backgroundColor = NewWhiteColor;
- if (indexPath.row == dataArray.count) {
- [collcell.incoImage setImage:NewImageNamed(@"AddMedia")];
- collcell.deleteButton.hidden = YES;
- }else{
- [collcell.incoImage setImage:NewImageNamed(@"")];
- collcell.deleteButton.hidden = NO;
- if (dataArray.count>0) {
- [collcell SetCollCellData:dataArray[indexPath.row]];
- }
- }
- collcell.deleteButton.tag = indexPath.row;
- NewTouchUpInside(collcell.deleteButton, deleteButtonclick:);
- return collcell;
- }
- #pragma mark --UICollectionViewDelegateFlowLayout
- //定义每个UICollectionView 的大小
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- return CGSizeMake(SCREEN_WIDTH/2-20, 100);
- }
- //定义每个UICollectionView 的 margin 边距 上左下右
- -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
- {
- return UIEdgeInsetsMake(0, 15, 0, 15);
- }
- #pragma mark --UICollectionViewDelegate
- //UICollectionView被选中时调用的方法
- -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.row == dataArray.count) {
- if([self.delegateColl respondsToSelector:@selector(CGPTColldelegateClickCooRow:)])
- {
- [self.delegateColl CGPTColldelegateClickCooRow:indexPath.row];
- }
- }else{
- NSLog(@"1");
- }
- // UICollectionViewCell * cell = (UICollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
- // cell.backgroundColor = [UIColor whiteColor];
- // //代理传值
- // CollCell *cell = (CollCell *)[collectionView cellForItemAtIndexPath:indexPath];
- // luoluo = indexPath.row;
- // [_CollView reloadData];
-
- }
- - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
- // CollCell *cell = (CollCell *)[collectionView cellForItemAtIndexPath:indexPath];
- // cell.type.textColor = NewButtonColor;
- // cell.type.backgroundColor = NewWhiteColor;
- // [_CollView reloadData];
-
- }
- - (void)reloadDatas:(NSMutableArray *)arr {
-
- [dataArray removeAllObjects];
- [dataArray addObjectsFromArray:arr];
- [_CollView reloadData];
- }
- - (void)deleteButtonclick:(UIButton *)sender {
- NSLog(@"111");
- if([self.delegateColl respondsToSelector:@selector(hahahaha:)])
- {
- [self.delegateColl hahahaha:sender.tag];
- }
- [dataArray removeObjectAtIndex:sender.tag];
- [_CollView reloadData];
- }
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- @end
|