collectionview接收到网络的传值

//

//  homepagetwoViewController.m

//  shoppingMall

//

//  Created by dasousuo on 2017/5/9.

//  Copyright © 2017 Forever. All rights reserved.

//


#import "homepagetwoViewController.h"

#import "XRCarouselView.h"

#import <Masonry.h>

#import <AFNetworking.h>

#import "NSObject+Netwoking.h"

#import "secondHeaderView.h"

#import "nutritiousViewController.h"

#import "snackcell.h"

#import "IPHelper.h"

#import "twoViewCell.h"

#import <SVProgressHUD.h>

#import <MJExtension.h>

#import "firstModel.h"

#import "picModel.h"

#import <MJRefresh.h>

#import "picModel.h"

#import "addcarViewController.h"

#import "shopcarViewController.h"

#import "hotelwebsiteViewController.h"

#import "abountusViewController.h"

#import "abouttwousViewController.h"

#import "moreViewController.h"

#import "twoModel.h"

#import <UIImageView+WebCache.h>

@interface homepagetwoViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,XRCarouselViewDelegate>


@property(nonatomic,strong)NSMutableArray <firstModel *>*snackmodels;


@property(nonatomic,strong)NSMutableArray *goodscount;

@property(nonatomic,strong)NSMutableArray *piccount;


@property(nonatomic,strong)NSMutableArray *picarray;

@property(nonatomic,strong)NSMutableArray *wordarray;


@property(nonatomic,strong)NSMutableArray <twoModel*>*twomodels;


@end


@implementation homepagetwoViewController

//字典转字符串

+ (NSString*)dictionaryToJson:(NSDictionary *)dic


{

    

    NSError *parseError = nil;

    

    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];

    

    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

    

}


-(NSMutableArray<twoModel*>*)twomodels{

    if (_twomodels==nil) {

        _twomodels = [NSMutableArray array];

    }

    return _twomodels;

}


-(NSMutableArray <firstModel *>*)snackmodels{

    if (_snackmodels==nil) {

        _snackmodels = [NSMutableArray array];

    }

    return _snackmodels;

}

-(NSMutableArray *)piccount{

    if (_piccount ==nil) {

        _piccount = [NSMutableArray array];

    }

    return _piccount;

}

-(void)viewWillAppear:(BOOL)animated{

//登录

    NSString *str = @"";


    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

    manager.responseSerializer = [AFCompoundResponseSerializer serializer];


    NSDictionary *dic = @{@"username":@"cih",@"password":@"cihcih"};

    NSMutableDictionary *mDic1 = [NSMutableDictionary dictionaryWithDictionary:dic];

    

    [manager POST:str parameters:mDic1 progress:^(NSProgress * _Nonnull uploadProgress) {

        

    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

        //获取cookie

        NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage]cookies];

        for (NSHTTPCookie *cookie in cookies) {

            NSString *cookiestr = [NSString stringWithFormat:@"%@=%@",cookie.name,cookie.value];

         

            NSUserDefaults *cookiedefault = [NSUserDefaults standardUserDefaults];

            [cookiedefault setObject:cookiestr forKey:@"cookie"];

            [cookiedefault synchronize];

            

        }

        

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        

    }];

    

}


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColor colorWithRed:1.0/255 green:148.0/255 blue:226.0/255 alpha:1];


    _collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:[UICollectionViewFlowLayout new]];

    [self.view addSubview:_collectionView];

    _collectionView.delegate = self;

    _collectionView.dataSource = self;

   // _collectionView.backgroundColor = [UIColor groupTableViewBackgroundColor];

    _collectionView.backgroundColor = [UIColor whiteColor];

    [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellone"];

    //添加头部视图

    [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"Header"];

    

    [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"Header3"];


    [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"Headertwo"];

    [_collectionView registerClass:[snackcell class] forCellWithReuseIdentifier:@"snackviewcell"];

    [_collectionView registerClass:[twoViewCell class] forCellWithReuseIdentifier:@"twoViewCell"];

    [_collectionView registerClass:[twoViewCell class] forCellWithReuseIdentifier:@"snackviewcell"];

    NSString *URLString = @"";

    

    [NSObject POST:URLString parameters:nil progress:^(NSProgress *downloadProgress) {

        

    } completionHandler:^(id responseObj, NSError *error) {

        

        NSArray *picarray = responseObj[@"data"];

        for (NSDictionary *dic in picarray) {

          

            NSArray *array = dic[@"pic"];

        

        

        }

        if ([responseObj[@"error"]integerValue]==0) {

            

            NSArray *array = responseObj[@"name"];

            for (NSDictionary *dic in array) {

                firstModel *model = [firstModel mj_objectWithKeyValues:dic];

                model.pic = [NSMutableArray array];

                NSMutableArray *goods = [NSMutableArray array];

                for (NSDictionary *dit in dic[@"pic"]) {

                    picModel *pmodel = [picModel mj_objectWithKeyValues:dit];

                  

                    

                    [goods addObject:pmodel];

                    [model.pic addObject:pmodel];

                }

                _piccount = goods;

                [_snackmodels addObject:model];


            }

            [self.collectionView reloadData];

        }else{

            //无返回数据

            

            [SVProgressHUD showErrorWithStatus:@"无数据"];

        }

        

    }];

    

    

    //two

    

    NSString *URLStringtwo = @"";

    [NSObject POST:URLStringtwo parameters:nil progress:^(NSProgress *downloadProgress) {

        

    } completionHandler:^(id responseObj, NSError *error) {

        // NSLog(@"获取十个cookie:%@",responseObj);

        NSMutableArray *picarray = [NSMutableArray array];

        NSMutableArray *wordarray = [NSMutableArray array];

        if ([responseObj[@"status"]integerValue]==1) {

            

            NSMutableArray *goods = [NSMutableArray array];

            for (NSDictionary *dic in responseObj[@"data"]) {

                

               // NSLog(@"输出字典的值:%@",dic);

                

                [wordarray addObject:dic[@"typeName"]];

                [picarray addObject:dic[@"minImage"]];

                

                

                twoModel *model = [twoModel mj_objectWithKeyValues:dic];

                NSLog(@"输出model.image:%@",model.minImage);

                

                [goods addObject:model];

                

            }

            _twomodels = goods;

            [self.collectionView reloadData];

        }else{

            

            [SVProgressHUD setMinimumDismissTimeInterval:1];

            [SVProgressHUD showErrorWithStatus:responseObj[@"msg"]];

        }

        

        _picArray = picarray;

        _wordarray = wordarray;

        //[_collectionView reloadData];

    }];

    

    NSLog(@"输出picarray:%@",_picArray);

    NSLog(@"输出wordarray:%@",_wordarray);

    

    _collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{

        

        [self updateData];

    }];

    

}

-(void)updateData{

    [self.collectionView reloadData];

     [self.collectionView.mj_header endRefreshing];

}

//询问 分区头部视图什么样

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section==0) {

        UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"Header" forIndexPath:indexPath];

        view.backgroundColor = [UIColor orangeColor];

        return view;

    }else if (indexPath.section==2){

        UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"Headertwo" forIndexPath:indexPath];

        view.backgroundColor = [UIColor groupTableViewBackgroundColor];

        //酒店网点btn

        UIButton *webbtn = [[UIButton alloc]init];

        webbtn.backgroundColor = [UIColor whiteColor];

        [webbtn addTarget:self action:@selector(clickwebtn) forControlEvents:UIControlEventTouchUpInside];

        [view addSubview:webbtn];

        [webbtn mas_makeConstraints:^(MASConstraintMaker *make) {

            make.left.mas_equalTo(0);

            make.top.mas_equalTo(0);

            make.bottom.mas_equalTo(0);

            make.width.mas_equalTo(view.mas_width).multipliedBy(0.5);

        }];

        

        UILabel *label = [[UILabel alloc]init];

        label.textColor = [UIColor blackColor];

        label.text = @"酒店网点";

        label.font = [UIFont systemFontOfSize:18];

        [webbtn addSubview:label];

        [label mas_makeConstraints:^(MASConstraintMaker *make) {

            make.centerX.mas_equalTo(webbtn.mas_centerX);

            make.top.mas_equalTo(20);

            make.size.mas_equalTo(CGSizeMake(90, 19));

        }];

        

        UILabel *labeltwo = [[UILabel alloc]init];

        labeltwo.textColor = [UIColor orangeColor];

        labeltwo.text = @"专业耐心的优质服务";

        labeltwo.font = [UIFont systemFontOfSize:14];

        [webbtn addSubview:labeltwo];

        [labeltwo mas_makeConstraints:^(MASConstraintMaker *make) {

            make.centerX.mas_equalTo(label.mas_centerX);

            make.top.mas_equalTo(label.mas_bottom).offset(10);

            make.size.mas_equalTo(CGSizeMake(130, 11));

        }];

        UIImageView *imageview = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"jiudian"]];

        [webbtn addSubview:imageview];

        [imageview mas_makeConstraints:^(MASConstraintMaker *make) {

            make.centerX.mas_equalTo(labeltwo.mas_centerX);

            make.top.mas_equalTo(labeltwo.mas_bottom).offset(10);

            make.size.mas_equalTo(CGSizeMake(80, 80));

        }];

        //购物车btn

        UIButton *shopcarbtn = [[UIButton alloc]init];

        shopcarbtn.backgroundColor = [UIColor whiteColor];

        [shopcarbtn addTarget:self action:@selector(clickshop) forControlEvents:UIControlEventTouchUpInside];

        [view addSubview:shopcarbtn];

        [shopcarbtn mas_makeConstraints:^(MASConstraintMaker *make) {

            make.left.mas_equalTo(webbtn.mas_right).offset(1);

            make.right.mas_equalTo(0);

            make.top.mas_equalTo(0);

            make.height.mas_equalTo(95);

        }];

        

        UILabel *shoplabel = [[UILabel alloc]init];

        shoplabel.textColor = [UIColor blackColor];

        shoplabel.text = @"购物车";

        shoplabel.font = [UIFont systemFontOfSize:18];

        [shopcarbtn addSubview:shoplabel];

        [shoplabel mas_makeConstraints:^(MASConstraintMaker *make) {

            make.top.mas_equalTo(10);

            make.centerX.mas_equalTo(shopcarbtn.mas_centerX);

            make.size.mas_equalTo(CGSizeMake(60, 19));

        }];

        //快来买单吧

        UILabel *orderlabel = [[UILabel alloc]init];

        orderlabel.text = @"快来买单啦!";

        orderlabel.textColor =[UIColor orangeColor];

        orderlabel.font = [UIFont systemFontOfSize:12];

        [shopcarbtn addSubview:orderlabel];

        [orderlabel mas_makeConstraints:^(MASConstraintMaker *make) {

            make.centerX.mas_equalTo(shopcarbtn.mas_centerX);

            make.top.mas_equalTo(shoplabel.mas_bottom).offset(5);

            make.size.mas_equalTo(CGSizeMake(80, 13));

        }];

        //购物车imageview

        UIImageView *shopview = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"gouwu"]];

        [shopcarbtn addSubview:shopview];

        [shopview mas_makeConstraints:^(MASConstraintMaker *make) {

            make.centerX.mas_equalTo(shopcarbtn.mas_centerX);

            make.top.mas_equalTo(orderlabel.mas_bottom).offset(2);

            make.size.mas_equalTo(CGSizeMake(40, 40));

        }];

        

        //关于我们

        UIButton *aboutbtn = [[UIButton alloc]init];

        aboutbtn.backgroundColor = [UIColor whiteColor];

        [aboutbtn addTarget:self action:@selector(aboutus) forControlEvents:UIControlEventTouchUpInside];

        [view addSubview:aboutbtn];

        [aboutbtn mas_makeConstraints:^(MASConstraintMaker *make) {

            make.left.mas_equalTo(shopcarbtn.mas_left);

            make.right.mas_equalTo(shopcarbtn.mas_right);

            make.top.mas_equalTo(shopcarbtn.mas_bottom).offset(1);

            make.bottom.mas_equalTo(0);

        }];

        

        UILabel *abounlabel = [[UILabel alloc]init];

        abounlabel.text = @"关于我们";

        abounlabel.textColor = [UIColor blackColor];

        abounlabel.font = [UIFont systemFontOfSize:18];

        [aboutbtn addSubview:abounlabel];

        [abounlabel mas_makeConstraints:^(MASConstraintMaker *make) {

            make.top.mas_equalTo(10);

            make.centerX.mas_equalTo(aboutbtn.mas_centerX);

            make.size.mas_equalTo(CGSizeMake(100, 19));

        }];

        UILabel *wellabel = [[UILabel alloc]init];

        wellabel.text = @"欢迎你来联系我们";

        wellabel.textAlignment = NSTextAlignmentCenter;

        wellabel.textColor = [UIColor orangeColor];

        wellabel.font = [UIFont systemFontOfSize:12];

        [aboutbtn addSubview:wellabel];

        [wellabel mas_makeConstraints:^(MASConstraintMaker *make) {

            make.top.mas_equalTo(abounlabel.mas_bottom).offset(5);

            make.centerX.mas_equalTo(aboutbtn.mas_centerX);

            make.size.mas_equalTo(CGSizeMake(150, 13));

        }];

        UIImageView *connectview = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"guanyu2"]];

        [aboutbtn addSubview:connectview];

        [connectview mas_makeConstraints:^(MASConstraintMaker *make) {

            make.centerX.mas_equalTo(abounlabel.mas_centerX);

            make.size.mas_equalTo(CGSizeMake(20, 20));

            make.bottom.mas_equalTo(-5);

        }];

        return view;

    }else if (indexPath.section==1){

      

        UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"Header" forIndexPath:indexPath];

        view.backgroundColor = [UIColor orangeColor];

        return view;

    }

    UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"Header3" forIndexPath:indexPath];

    view.backgroundColor = [UIColor greenColor];

    

    UIImageView *bannerview = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"750210"]];

    [view addSubview:bannerview];

    [bannerview mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(0);

        make.top.mas_equalTo(0);

        make.right.mas_equalTo(0);

        make.height.mas_equalTo(100);

    }];

    

    UIView *twoview = [[UIView alloc]init];

    twoview.backgroundColor = [UIColor whiteColor];

    [view addSubview:twoview];

    [twoview mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(0);

        make.right.mas_equalTo(0);

        make.top.mas_equalTo(bannerview.mas_bottom).offset(5);

        make.height.mas_equalTo(50);

    }];

    

    UIImageView *imageview = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"dan"]];

    [twoview addSubview:imageview];

    [imageview mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(10);

        make.centerY.mas_equalTo(twoview.mas_centerY);

        make.size.mas_equalTo(CGSizeMake(30, 30));

    }];

    

    UILabel *labelthree = [[UILabel alloc]init];

    firstModel *model = self.snackmodels[indexPath.section-3];

    labelthree.text = model.name;

   // labelthree.text = @"食品分类";

    labelthree.textColor = [UIColor blackColor];

    [twoview addSubview:labelthree];

    [labelthree mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(imageview.mas_right).offset(10);

        make.centerY.mas_equalTo(imageview.mas_centerY);

        make.size.mas_equalTo(CGSizeMake(120, 19));

    }];

    

    UIButton *morebtn = [[UIButton alloc]init];

    [morebtn setTitle:@"更多>>" forState:UIControlStateNormal];

    [morebtn setTitleColor:[UIColor colorWithRed:1.0/255 green:148.0/255 blue:226.0/255 alpha:1] forState:UIControlStateNormal];

    [morebtn addTarget:self action:@selector(clickmore) forControlEvents:UIControlEventTouchUpInside];

    [twoview addSubview:morebtn];

    [morebtn mas_makeConstraints:^(MASConstraintMaker *make) {

        make.right.mas_equalTo(-10);

        make.centerY.mas_equalTo(twoview.mas_centerY);

        make.size.mas_equalTo(CGSizeMake(60, 19));

    }];

    return view;

}

-(void)aboutus{

    NSLog(@"关于我们");

    

    abouttwousViewController *abouttwo = [abouttwousViewController new];

    

    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:abouttwo];

    [self presentViewController:nav animated:YES completion:nil];


}

-(void)clickmore{

    nutritiousViewController *nutritious = [[nutritiousViewController alloc]init];

    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:nutritious];

    [self presentViewController:nav animated:YES completion:nil];


}

-(void)clickshop{

    NSLog(@"点击购物车");

    shopcarViewController *shopcar = [shopcarViewController new];

    

    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:shopcar];

    [self presentViewController:nav animated:YES completion:nil];

  

}

-(void)clickwebtn{

    NSLog(@"点击酒店网点");

    

    hotelwebsiteViewController *hotelwebsite = [hotelwebsiteViewController new];

    //[self presentViewController:hotelwebsite animated:YES completion:nil];

    //[self.navigationController pushViewController:hotelwebsite animated:YES];

    

    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:hotelwebsite];

    [self presentViewController:nav animated:YES completion:nil];

    

}

-(void)carouselView:(XRCarouselView *)carouselView clickImageAtIndex:(NSInteger)index

{


    

    NSLog(@"添击崩");

}


//定义头部视图显示的大小

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{

    if (section==0) {

        return CGSizeMake(self.view.frame.size.width, 0);

    }else if (section==1){

        return CGSizeMake(self.view.frame.size.width, 0);

    }else if (section==2){

        return CGSizeMake(self.view.frame.size.width, 170);

    }

    return CGSizeMake(self.view.bounds.size.width, 155);

}


-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

    return 3+ self.snackmodels.count;

}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    if (section==0) {

        return 1;

    } else if (section==1){

        return _twomodels.count;

    }else if (section==2){

        return 0;

    } else {

        return  self.snackmodels[section-3].pic.count;

    }

   

}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section==0) {

        UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellone" forIndexPath:indexPath];

        //cell.backgroundColor = [UIColor redColor];

        

        //发送网络请求

        

        //登录成功 获取banner

        

        NSString *URLString = @"http://dss.gebixianxiang.com/getBanner";

        [NSObject POST:URLString parameters:nil progress:^(NSProgress *downloadProgress) {

            

        } completionHandler:^(id responseObj, NSError *error) {

            

           

            

            NSArray *datarray = responseObj[@"data"];

            NSMutableArray *imageName = [NSMutableArray array];

            for (NSDictionary *dic in datarray) {


                NSString *photostr = dic[@"photo"];

                

                [imageName addObject:photostr];

            }

            

            self.cousView.imageArray = imageName;

            self.cousView.delegate = self;

            

            

        }];

        _cousView.time = 2;

        //设置分页控件的位置,默认为PositionBottomCenter

        _cousView.pagePosition = PositionBottomCenter;

        UIColor *bgColor = [[UIColor blueColor] colorWithAlphaComponent:0.5];

        UIFont *font = [UIFont systemFontOfSize:15];

        UIColor *textColor = [UIColor greenColor];

        // _cousview.backgroundColor = [UIColor redColor];

        [_cousView setDescribeTextColor:textColor font:font bgColor:bgColor];

        if (!_cousView) {

            //_cousView = [[XRCarouselView alloc]initWithFrame:CGRectMake(0, 20, self.view.frame.size.width,150)];

            _cousView = [[XRCarouselView alloc]init];

            [cell.contentView addSubview:_cousView];

            [_cousView mas_makeConstraints:^(MASConstraintMaker *make) {

                make.left.mas_equalTo(0);

                make.top.mas_equalTo(0);

                make.right.mas_equalTo(0);

                //make.bottom.mas_equalTo(0);

                make.height.mas_equalTo(180);

            }];

        }


        return cell;

    }else if (indexPath.section==1){

        

        static NSString *identify = @"twoViewCell";

        twoViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identify forIndexPath:indexPath];

        collectionView.backgroundColor = [UIColor whiteColor];

        collectionView.backgroundColor = [UIColor colorWithRed:240.0/255 green:240.0/255 blue:240.0/255 alpha:1];

        cell.backgroundColor = [UIColor whiteColor];

       

            

        twoModel *modeltwo = _twomodels[indexPath.item];

        cell.textLabel.text = modeltwo.typeName;

        NSString *urlstring = [modeltwo.minImage stringByReplacingOccurrencesOfString:@"\"" withString:@""];

        [cell.imgView sd_setImageWithURL:[NSURL URLWithString:urlstring] placeholderImage:[UIImage imageNamed:@"1.jpg"]];

        return cell;

    } else {

        if (indexPath.section == 2) {

            static NSString *identify = @"twoViewCell";

            twoViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identify forIndexPath:indexPath];

            return cell;

        }

        static NSString *identify = @"snackviewcell";

        snackcell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identify forIndexPath:indexPath];

        //[cell sizeToFit];

        //NSLog(@"%@",self.snackmodels);

 

        firstModel *model = self.snackmodels[indexPath.section-3];

        if (model.pic.count != 0) {

            

            picModel *picmodel = model.pic[0];

            cell.imgView.image = [UIImage imageNamed:@"shutiao"];

            //NSLog(@"输出picmodelpicture的值:%@",model.photo);

            cell.textLabel.text = picmodel.name;

            cell.bottomLabel.text = @"乐享生活每一天";

        }


        return cell;

    }

}

//定义分区距离四边缘的距离

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{

//    if (section==0) {

//        return UIEdgeInsetsMake(10, 10, 10, 10);

//    }else if (section==1){

//        return UIEdgeInsetsMake(10, 10, 10, 10);

//    }else if (section==2){

//        return UIEdgeInsetsMake(10, 10, 10, 10);

//    }

    return UIEdgeInsetsMake(10, 10, 10, 10);

}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section==0) {

        return CGSizeMake(self.view.frame.size.width, 180);

    }else if (indexPath.section==1){

        CGFloat width = (self.view.bounds.size.width-6*10)/5;

        return CGSizeMake(width, width);

    }else if (indexPath.section==2){

        return CGSizeMake(0, 0);

    }

    //CGFloat width = (self.view.bounds.size.width-3*10)/2;

    // CGFloat width = 100.0;

    CGFloat width = (self.view.bounds.size.width-24)/3;

    return CGSizeMake(width, width+50);

}

//设置行间距

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{

    if (section==0) {

        return 10;

    }else if (section==1){

        

        //NSLog(@"输出picarray.count:%lu",(unsigned long)_picarray.count);

        return 10;

    }else if (section==2){

        return 10;

    }

    return 1;

}

//设置列间距

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{

    return 1;

}


-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section==3) {

        NSLog(@"点击购物车");

        

        addcarViewController *addcar = [addcarViewController new];

        [self presentViewController:addcar animated:YES completion:nil];

        

    

    }

    nutritiousViewController *nutritious = [[nutritiousViewController alloc]init];

    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:nutritious];

    [self presentViewController:nav animated:YES completion:nil];

    

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值