collectionview接收到网络的传值
来源:互联网 发布:java cs 框架 编辑:程序博客网 时间:2024/06/14 22:00
//
// 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>
@interfacehomepagetwoViewController ()<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 = [NSJSONSerializationdataWithJSONObject:dicoptions:NSJSONWritingPrettyPrintederror:&parseError];
return [[NSStringalloc]initWithData:jsonDataencoding:NSUTF8StringEncoding];
}
-(NSMutableArray<twoModel*>*)twomodels{
if (_twomodels==nil) {
_twomodels = [NSMutableArrayarray];
}
return_twomodels;
}
-(NSMutableArray <firstModel *>*)snackmodels{
if (_snackmodels==nil) {
_snackmodels = [NSMutableArrayarray];
}
return_snackmodels;
}
-(NSMutableArray *)piccount{
if (_piccount ==nil) {
_piccount = [NSMutableArrayarray];
}
return_piccount;
}
-(void)viewWillAppear:(BOOL)animated{
//登录
NSString *str =@"";
AFHTTPSessionManager *manager = [AFHTTPSessionManagermanager];
manager.responseSerializer = [AFCompoundResponseSerializerserializer];
NSDictionary *dic =@{@"username":@"cih",@"password":@"cihcih"};
NSMutableDictionary *mDic1 = [NSMutableDictionarydictionaryWithDictionary:dic];
[manager POST:strparameters:mDic1progress:^(NSProgress *_Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task,id _Nullable responseObject) {
//获取cookie
NSArray *cookies = [[NSHTTPCookieStoragesharedHTTPCookieStorage]cookies];
for (NSHTTPCookie *cookiein cookies) {
NSString *cookiestr = [NSStringstringWithFormat:@"%@=%@",cookie.name,cookie.value];
NSUserDefaults *cookiedefault = [NSUserDefaultsstandardUserDefaults];
[cookiedefault setObject:cookiestrforKey:@"cookie"];
[cookiedefault synchronize];
}
} failure:^(NSURLSessionDataTask * _Nullable task,NSError *_Nonnull error) {
}];
}
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColorcolorWithRed:1.0/255green:148.0/255blue:226.0/255alpha:1];
_collectionView = [[UICollectionViewalloc]initWithFrame:self.view.boundscollectionViewLayout:[UICollectionViewFlowLayoutnew]];
[self.viewaddSubview:_collectionView];
_collectionView.delegate = self;
_collectionView.dataSource = self;
// _collectionView.backgroundColor = [UIColor groupTableViewBackgroundColor];
_collectionView.backgroundColor = [UIColorwhiteColor];
[_collectionViewregisterClass:[UICollectionViewCellclass]forCellWithReuseIdentifier:@"cellone"];
//添加头部视图
[_collectionViewregisterClass:[UICollectionReusableViewclass]forSupplementaryViewOfKind:UICollectionElementKindSectionHeaderwithReuseIdentifier:@"Header"];
[_collectionViewregisterClass:[UICollectionReusableViewclass]forSupplementaryViewOfKind:UICollectionElementKindSectionHeaderwithReuseIdentifier:@"Header3"];
[_collectionViewregisterClass:[UICollectionReusableViewclass]forSupplementaryViewOfKind:UICollectionElementKindSectionHeaderwithReuseIdentifier:@"Headertwo"];
[_collectionViewregisterClass:[snackcellclass]forCellWithReuseIdentifier:@"snackviewcell"];
[_collectionViewregisterClass:[twoViewCellclass]forCellWithReuseIdentifier:@"twoViewCell"];
[_collectionViewregisterClass:[twoViewCellclass]forCellWithReuseIdentifier:@"snackviewcell"];
NSString *URLString =@"";
[NSObjectPOST:URLStringparameters:nilprogress:^(NSProgress *downloadProgress) {
} completionHandler:^(id responseObj,NSError *error) {
NSArray *picarray = responseObj[@"data"];
for (NSDictionary *dicin picarray) {
NSArray *array = dic[@"pic"];
}
if ([responseObj[@"error"]integerValue]==0) {
NSArray *array = responseObj[@"name"];
for (NSDictionary *dicin array) {
firstModel *model = [firstModelmj_objectWithKeyValues:dic];
model.pic = [NSMutableArrayarray];
NSMutableArray *goods = [NSMutableArrayarray];
for (NSDictionary *ditin dic[@"pic"]) {
picModel *pmodel = [picModelmj_objectWithKeyValues:dit];
[goods addObject:pmodel];
[model.picaddObject:pmodel];
}
_piccount = goods;
[_snackmodelsaddObject:model];
}
[self.collectionViewreloadData];
}else{
//无返回数据
[SVProgressHUDshowErrorWithStatus:@"无数据"];
}
}];
//two
NSString *URLStringtwo =@"";
[NSObjectPOST:URLStringtwoparameters:nilprogress:^(NSProgress *downloadProgress) {
} completionHandler:^(id responseObj,NSError *error) {
// NSLog(@"获取十个cookie:%@",responseObj);
NSMutableArray *picarray = [NSMutableArrayarray];
NSMutableArray *wordarray = [NSMutableArrayarray];
if ([responseObj[@"status"]integerValue]==1) {
NSMutableArray *goods = [NSMutableArrayarray];
for (NSDictionary *dicin responseObj[@"data"]) {
// NSLog(@"输出字典的值:%@",dic);
[wordarray addObject:dic[@"typeName"]];
[picarray addObject:dic[@"minImage"]];
twoModel *model = [twoModelmj_objectWithKeyValues:dic];
NSLog(@"输出model.image:%@",model.minImage);
[goods addObject:model];
}
_twomodels = goods;
[self.collectionViewreloadData];
}else{
[SVProgressHUDsetMinimumDismissTimeInterval:1];
[SVProgressHUDshowErrorWithStatus:responseObj[@"msg"]];
}
_picArray = picarray;
_wordarray = wordarray;
//[_collectionView reloadData];
}];
NSLog(@"输出picarray:%@",_picArray);
NSLog(@"输出wordarray:%@",_wordarray);
_collectionView.mj_header = [MJRefreshNormalHeaderheaderWithRefreshingBlock:^{
[selfupdateData];
}];
}
-(void)updateData{
[self.collectionViewreloadData];
[self.collectionView.mj_headerendRefreshing];
}
//询问分区头部视图什么样
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==0) {
UICollectionReusableView *view = [collectionViewdequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeaderwithReuseIdentifier:@"Header"forIndexPath:indexPath];
view.backgroundColor = [UIColororangeColor];
return view;
}elseif (indexPath.section==2){
UICollectionReusableView *view = [collectionViewdequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeaderwithReuseIdentifier:@"Headertwo"forIndexPath:indexPath];
view.backgroundColor = [UIColorgroupTableViewBackgroundColor];
//酒店网点btn
UIButton *webbtn = [[UIButtonalloc]init];
webbtn.backgroundColor = [UIColorwhiteColor];
[webbtnaddTarget:selfaction:@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 = [[UILabelalloc]init];
label.textColor = [UIColorblackColor];
label.text =@"酒店网点";
label.font = [UIFontsystemFontOfSize: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 = [[UILabelalloc]init];
labeltwo.textColor = [UIColororangeColor];
labeltwo.text =@"专业耐心的优质服务";
labeltwo.font = [UIFontsystemFontOfSize: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 = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"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 = [[UIButtonalloc]init];
shopcarbtn.backgroundColor = [UIColorwhiteColor];
[shopcarbtnaddTarget:selfaction:@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 = [[UILabelalloc]init];
shoplabel.textColor = [UIColorblackColor];
shoplabel.text =@"购物车";
shoplabel.font = [UIFontsystemFontOfSize: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 = [[UILabelalloc]init];
orderlabel.text =@"快来买单啦!";
orderlabel.textColor =[UIColororangeColor];
orderlabel.font = [UIFontsystemFontOfSize: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 = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"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 = [[UIButtonalloc]init];
aboutbtn.backgroundColor = [UIColorwhiteColor];
[aboutbtnaddTarget:selfaction:@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 = [[UILabelalloc]init];
abounlabel.text =@"关于我们";
abounlabel.textColor = [UIColorblackColor];
abounlabel.font = [UIFontsystemFontOfSize: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 = [[UILabelalloc]init];
wellabel.text =@"欢迎你来联系我们";
wellabel.textAlignment =NSTextAlignmentCenter;
wellabel.textColor = [UIColororangeColor];
wellabel.font = [UIFontsystemFontOfSize: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 = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"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;
}elseif (indexPath.section==1){
UICollectionReusableView *view = [collectionViewdequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeaderwithReuseIdentifier:@"Header"forIndexPath:indexPath];
view.backgroundColor = [UIColororangeColor];
return view;
}
UICollectionReusableView *view = [collectionViewdequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeaderwithReuseIdentifier:@"Header3"forIndexPath:indexPath];
view.backgroundColor = [UIColorgreenColor];
UIImageView *bannerview = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"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 = [[UIViewalloc]init];
twoview.backgroundColor = [UIColorwhiteColor];
[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 = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"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 = [[UILabelalloc]init];
firstModel *model =self.snackmodels[indexPath.section-3];
labelthree.text = model.name;
// labelthree.text = @"食品分类";
labelthree.textColor = [UIColorblackColor];
[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 = [[UIButtonalloc]init];
[morebtn setTitle:@"更多>>"forState:UIControlStateNormal];
[morebtn setTitleColor:[UIColorcolorWithRed:1.0/255green:148.0/255blue:226.0/255alpha:1]forState:UIControlStateNormal];
[morebtn addTarget:selfaction:@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 = [abouttwousViewControllernew];
UINavigationController *nav = [[UINavigationControlleralloc]initWithRootViewController:abouttwo];
[selfpresentViewController:navanimated:YEScompletion:nil];
}
-(void)clickmore{
nutritiousViewController *nutritious = [[nutritiousViewControlleralloc]init];
UINavigationController *nav = [[UINavigationControlleralloc]initWithRootViewController:nutritious];
[selfpresentViewController:navanimated:YEScompletion:nil];
}
-(void)clickshop{
NSLog(@"点击购物车");
shopcarViewController *shopcar = [shopcarViewControllernew];
UINavigationController *nav = [[UINavigationControlleralloc]initWithRootViewController:shopcar];
[selfpresentViewController:navanimated:YEScompletion:nil];
}
-(void)clickwebtn{
NSLog(@"点击酒店网点");
hotelwebsiteViewController *hotelwebsite = [hotelwebsiteViewControllernew];
//[self presentViewController:hotelwebsite animated:YES completion:nil];
//[self.navigationController pushViewController:hotelwebsite animated:YES];
UINavigationController *nav = [[UINavigationControlleralloc]initWithRootViewController:hotelwebsite];
[selfpresentViewController:navanimated:YEScompletion:nil];
}
-(void)carouselView:(XRCarouselView *)carouselView clickImageAtIndex:(NSInteger)index
{
NSLog(@"添击崩");
}
//定义头部视图显示的大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
if (section==0) {
returnCGSizeMake(self.view.frame.size.width,0);
}elseif (section==1){
returnCGSizeMake(self.view.frame.size.width,0);
}elseif (section==2){
returnCGSizeMake(self.view.frame.size.width,170);
}
returnCGSizeMake(self.view.bounds.size.width,155);
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return3+self.snackmodels.count;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
if (section==0) {
return1;
} elseif (section==1){
return_twomodels.count;
}elseif (section==2){
return0;
} else {
return self.snackmodels[section-3].pic.count;
}
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==0) {
UICollectionViewCell *cell = [collectionViewdequeueReusableCellWithReuseIdentifier:@"cellone"forIndexPath:indexPath];
//cell.backgroundColor = [UIColor redColor];
//发送网络请求
//登录成功获取banner图
NSString *URLString =@"http://dss.gebixianxiang.com/getBanner";
[NSObjectPOST:URLStringparameters:nilprogress:^(NSProgress *downloadProgress) {
} completionHandler:^(id responseObj,NSError *error) {
NSArray *datarray = responseObj[@"data"];
NSMutableArray *imageName = [NSMutableArrayarray];
for (NSDictionary *dicin 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 = [[UIColorblueColor]colorWithAlphaComponent:0.5];
UIFont *font = [UIFontsystemFontOfSize:15];
UIColor *textColor = [UIColorgreenColor];
// _cousview.backgroundColor = [UIColor redColor];
[_cousViewsetDescribeTextColor:textColorfont:fontbgColor:bgColor];
if (!_cousView) {
//_cousView = [[XRCarouselView alloc]initWithFrame:CGRectMake(0, 20, self.view.frame.size.width,150)];
_cousView = [[XRCarouselViewalloc]init];
[cell.contentViewaddSubview:_cousView];
[_cousViewmas_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;
}elseif (indexPath.section==1){
staticNSString *identify =@"twoViewCell";
twoViewCell *cell = [collectionViewdequeueReusableCellWithReuseIdentifier:identifyforIndexPath:indexPath];
collectionView.backgroundColor = [UIColorwhiteColor];
collectionView.backgroundColor = [UIColorcolorWithRed:240.0/255green:240.0/255blue:240.0/255alpha:1];
cell.backgroundColor = [UIColorwhiteColor];
twoModel *modeltwo =_twomodels[indexPath.item];
cell.textLabel.text = modeltwo.typeName;
NSString *urlstring = [modeltwo.minImagestringByReplacingOccurrencesOfString:@"\""withString:@""];
[cell.imgViewsd_setImageWithURL:[NSURLURLWithString:urlstring]placeholderImage:[UIImageimageNamed:@"1.jpg"]];
return cell;
} else {
if (indexPath.section ==2) {
staticNSString *identify =@"twoViewCell";
twoViewCell *cell = [collectionViewdequeueReusableCellWithReuseIdentifier:identifyforIndexPath:indexPath];
return cell;
}
staticNSString *identify =@"snackviewcell";
snackcell *cell = [collectionViewdequeueReusableCellWithReuseIdentifier:identifyforIndexPath: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 = [UIImageimageNamed:@"shutiao"];
//NSLog(@"输出picmodel的picture的值:%@",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);
// }
returnUIEdgeInsetsMake(10,10,10,10);
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==0) {
returnCGSizeMake(self.view.frame.size.width,180);
}elseif (indexPath.section==1){
CGFloat width = (self.view.bounds.size.width-6*10)/5;
returnCGSizeMake(width, width);
}elseif (indexPath.section==2){
returnCGSizeMake(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;
returnCGSizeMake(width, width+50);
}
//设置行间距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
if (section==0) {
return10;
}elseif (section==1){
//NSLog(@"输出picarray.count:%lu",(unsigned long)_picarray.count);
return10;
}elseif (section==2){
return10;
}
return1;
}
//设置列间距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
return1;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==3) {
NSLog(@"点击购物车");
addcarViewController *addcar = [addcarViewControllernew];
[selfpresentViewController:addcaranimated:YEScompletion:nil];
}
nutritiousViewController *nutritious = [[nutritiousViewControlleralloc]init];
UINavigationController *nav = [[UINavigationControlleralloc]initWithRootViewController:nutritious];
[selfpresentViewController:navanimated:YEScompletion:nil];
}
- collectionview接收到网络的传值
- collectionView的流布局实现从左面到右面排列
- collectionView 滚动到制定位置
- 网络包的接收过程
- Linux 内核网络协议栈 ------ tcp_ack 函数处理接收到的ACK包之后
- c#网络通信框架networkcomms内核解析之六 处理接收到的二进制数据
- 多种Cell的CollectionView
- 关于collectionview的初始化
- CollectionView的使用
- collectionView的用法
- collectionView的注意事项
- 神奇的 collectionview
- collectionView的使用iOS
- iOS collectionView的使用
- collectionView的反弹效果
- 自定义重排的CollectionView
- collectionView的进阶
- iOS 分组的CollectionView
- 1041. 考试座位号(15)
- c++inline内联函数
- Bayer Pattern
- 选择H5响应式网站建设的主要原因
- yii数据库常用操作
- collectionview接收到网络的传值
- 关于android的状态栏显示问题(AndroidStatusBar)
- 20170503cpp上机作业---派生构造
- django-自定义中间件
- CentOS7 Failed to start LSB: Bring up/down解决方法
- apache虚拟主机
- Mysql插入中文报错
- 端午节,原来还有这些历史意义!
- 判断堆中的对象是否活着