新UI马甲包

FSSuperListCell.m 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // FSSuperListCell.m
  3. // FSScrollViewNestTableViewDemo
  4. //
  5. // Created by liuxueli on 2018/12/11.
  6. // Copyright © 2018 fengshun. All rights reserved.
  7. //
  8. #import "FSSuperListCell.h"
  9. #import "LDSuperListCell.h"
  10. #import "LDSearchCoupleWebViewController.h"
  11. #import "LDSuperListModel.h"
  12. #import "HCLoginViewController.h"
  13. #import <AlibabaAuthSDK/ALBBSession.h>
  14. #import "AccountTool.h"
  15. #import <AlibabaAuthSDK/ALBBSDK.h>
  16. @implementation FSSuperListCell
  17. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  18. {
  19. self =[super initWithStyle:style reuseIdentifier:reuseIdentifier];
  20. if (self) {
  21. CGRect collectionViewFrame= CGRectMake(0, 0,SCREEN_WIDTH, 400);
  22. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  23. // 每一行cell之间的间距
  24. flowLayout.minimumLineSpacing = FITSIZE(5);
  25. // // 每一列cell之间的间距
  26. flowLayout.minimumInteritemSpacing = FITSIZE(5);
  27. // // 设置第一个cell和最后一个cell,与父控件之间的间距
  28. flowLayout.sectionInset = UIEdgeInsetsMake(FITSIZE(10), FITSIZE(8),FITSIZE(10), FITSIZE(8));
  29. flowLayout.itemSize = CGSizeMake((SCREEN_WIDTH-FITSIZE(31))/4, (SCREEN_WIDTH-FITSIZE(31))/4);// 该行代码就算不写,item也会有默认尺寸
  30. UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:collectionViewFrame collectionViewLayout:flowLayout];
  31. collectionView.backgroundColor = [UIColor clearColor];
  32. collectionView.dataSource = self;
  33. collectionView.delegate = self;
  34. _collections = collectionView;
  35. _collections.showsVerticalScrollIndicator=NO;
  36. _collections.showsHorizontalScrollIndicator=NO;
  37. _collections.layer.masksToBounds=YES;
  38. _collections.scrollEnabled=NO;
  39. [self.collections registerClass:[LDSuperListCell class] forCellWithReuseIdentifier:@"cellId"];
  40. [self addSubview:_collections];
  41. }
  42. return self;
  43. }
  44. -(void)setArray:(NSArray *)array
  45. {
  46. _array = array;
  47. if (self.array.count %4 == 0) {
  48. self.collections.frame=CGRectMake(0, 0, SCREEN_WIDTH, (self.array.count/4)*((SCREEN_WIDTH-FITSIZE(31))/4+FITSIZE(10))) ;
  49. }else{
  50. self.collections.frame=CGRectMake(0, 0, SCREEN_WIDTH, (self.array.count/4+1)*((SCREEN_WIDTH-FITSIZE(31))/4+FITSIZE(10)));
  51. }
  52. [self.collections reloadData];
  53. }
  54. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  55. return self.array.count;
  56. }
  57. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  58. LDSuperListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndexPath:indexPath];
  59. if (!cell ) {
  60. cell = [[LDSuperListCell alloc] init];
  61. }
  62. //品牌还在添加中。敬请期待。。
  63. cell.models=self.array[indexPath.row];
  64. cell.backgroundColor = [UIColor whiteColor];
  65. return cell;
  66. }
  67. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  68. {
  69. LDSuperListModel *model= self.array[indexPath.row];
  70. //点击大牌商品
  71. LDSearchCoupleWebViewController *searchCoupleWeb = [[LDSearchCoupleWebViewController alloc] init];
  72. searchCoupleWeb.url = model.url;
  73. searchCoupleWeb.jsString = model.ios_js_string;
  74. searchCoupleWeb.name = model.name;
  75. if ([[ALBBSession sharedInstance] isLogin] && [AccountTool isLogin]) {
  76. //进入
  77. [[self currentViewController].navigationController pushViewController:searchCoupleWeb animated:YES];
  78. }else if (![AccountTool isLogin]) {
  79. //未登录
  80. HCLoginViewController *login = [[HCLoginViewController alloc] init];
  81. [[self currentViewController] presentViewController:login animated:YES completion:nil];
  82. }else if (![[ALBBSession sharedInstance] isLogin]) {
  83. //淘宝未授权
  84. ALBBSDK *albbSDK = [ALBBSDK sharedInstance];
  85. [albbSDK setAppkey:ALBC_APP_KEY];
  86. [albbSDK setAuthOption:NormalAuth];
  87. [albbSDK auth:[self currentViewController] successCallback:^(ALBBSession *session){
  88. [[NSNotificationCenter defaultCenter] postNotificationName:ChangeTaoBaoAuthor object:nil];
  89. [[self currentViewController].navigationController pushViewController:searchCoupleWeb animated:YES];
  90. } failureCallback:^(ALBBSession *session,NSError *error){
  91. NSLog(@"session == %@,error == %@",session,error);
  92. }];
  93. }
  94. }
  95. - (UIViewController *)currentViewController{
  96. UIViewController * currVC = nil;
  97. UIWindow *window = [UIApplication sharedApplication].delegate.window;
  98. UIViewController * Rootvc = window.rootViewController;
  99. do {
  100. if ([Rootvc isKindOfClass:[UINavigationController class]]) {
  101. UINavigationController * nav = (UINavigationController *)Rootvc;
  102. UIViewController * v = [nav.viewControllers lastObject];
  103. currVC = v;
  104. Rootvc = v.presentedViewController;
  105. continue;
  106. }else if([Rootvc isKindOfClass:[UITabBarController class]]){
  107. UITabBarController * tabVC = (UITabBarController *)Rootvc;
  108. currVC = tabVC;
  109. Rootvc = [tabVC.viewControllers objectAtIndex:tabVC.selectedIndex];
  110. continue;
  111. }
  112. } while (Rootvc!=nil);
  113. return currVC;
  114. }
  115. @end