dkahgld

ZBHotSaleViewController.m 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // ZBHotSaleViewController.m
  3. // ZBProject
  4. //
  5. // Created by 学丽 on 2019/4/19.
  6. // Copyright © 2019 ZB. All rights reserved.
  7. //
  8. #import "ZBHotSaleViewController.h"
  9. @interface ZBHotSaleViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
  10. @property(nonatomic,strong)UICollectionView *collectionV;
  11. @property(nonatomic,strong)NSMutableArray *dataArray;
  12. @property(nonatomic,assign)NSInteger Page;
  13. @end
  14. @implementation ZBHotSaleViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. [self setNavs];
  18. }
  19. #pragma mark----collectionView||delegate&Datasource
  20. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  21. {
  22. ZBHotSaleListCell *shopC =[collectionView dequeueReusableCellWithReuseIdentifier:@"data" forIndexPath:indexPath];
  23. // shopC.model=self.dataArray[indexPath.row];
  24. return shopC;
  25. }
  26. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  27. {
  28. ZBGoodDetailVC *detailVC = [[ZBGoodDetailVC alloc] init];
  29. detailVC.model = self.dataArray[indexPath.row];
  30. [self.navigationController pushViewController:detailVC animated:YES];
  31. }
  32. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  33. {
  34. return CGSizeMake(SCREEN_WIDTH, 130);
  35. }
  36. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  37. {
  38. return 4;
  39. // return self.dataArray.count;
  40. }
  41. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  42. {
  43. return 1;
  44. }
  45. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  46. {
  47. return UIEdgeInsetsMake(0, 0, 0, 0);//分别为上、左、下、右
  48. }
  49. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
  50. {
  51. return CGSizeMake(SCREEN_WIDTH, 0);
  52. }
  53. -(void)setNavs
  54. {
  55. self.Page = 1;
  56. [self.view addSubview:self.collectionV];
  57. [self.collectionV mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.left.mas_equalTo(0);
  59. make.right.mas_equalTo(0);
  60. make.top.mas_equalTo(NavBarHeight);
  61. make.height.mas_equalTo(SCREEN_HEIGHT);
  62. }];
  63. self.view.backgroundColor=[UIColor lineColor];
  64. self.navBar.backgroundColor=[UIColor whiteColor];
  65. self.navBar.navTitleLabel.textColor=[UIColor blackColor];
  66. self.navBar.navTitleLabel.text=@"热销榜";
  67. self.navigationController.navigationBar.hidden=NO;
  68. UIButton *returnBtn =[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 30, 20)];
  69. [returnBtn addTarget:self action:@selector(returnClickBtn) forControlEvents:UIControlEventTouchUpInside];
  70. [returnBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
  71. returnBtn.adjustsImageWhenHighlighted = NO;
  72. [self.navBar setCustomLeftButtons:@[returnBtn]];
  73. [self.navBar setShowNavigationBarBottomLine:YES];
  74. }
  75. -(void)viewWillDisappear:(BOOL)animated
  76. {
  77. [super viewWillDisappear:animated];
  78. self.navigationController.navigationBar.hidden=NO;
  79. }
  80. -(void)viewWillAppear:(BOOL)animated
  81. {
  82. [super viewWillAppear:animated];
  83. self.navBar.hidden=NO;
  84. [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleDefault;
  85. }
  86. -(void)returnClickBtn
  87. {
  88. [self.navigationController popViewControllerAnimated:YES];
  89. }
  90. -(UICollectionView *)collectionV
  91. {
  92. if (!_collectionV) {
  93. UICollectionViewFlowLayout *flowLayout =[[UICollectionViewFlowLayout alloc]init];
  94. flowLayout.minimumLineSpacing = 1;
  95. flowLayout.minimumInteritemSpacing = 0;
  96. _collectionV =[[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) collectionViewLayout:flowLayout];
  97. _collectionV.delegate=self;
  98. _collectionV.dataSource=self;
  99. _collectionV.showsVerticalScrollIndicator=NO;
  100. _collectionV.showsHorizontalScrollIndicator=NO;
  101. _collectionV.backgroundColor=[UIColor clearColor];
  102. [_collectionV registerClass:[ZBHotSaleListCell class] forCellWithReuseIdentifier:@"data"];
  103. self.collectionV.mj_header =[MJRefreshNormalHeader headerWithRefreshingBlock:^{
  104. self.Page = 1;
  105. // [self getProductData];
  106. }];
  107. self.collectionV.mj_footer=[MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  108. self.Page ++;
  109. // [self getProductData];
  110. }];
  111. }
  112. return _collectionV;
  113. }
  114. -(NSMutableArray *)dataArray
  115. {
  116. if (!_dataArray) {
  117. _dataArray =[NSMutableArray array];
  118. }
  119. return _dataArray;
  120. }
  121. @end