123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- //
- // FSSuperListCell.m
- // FSScrollViewNestTableViewDemo
- //
- // Created by liuxueli on 2018/12/11.
- // Copyright © 2018 fengshun. All rights reserved.
- //
- #import "FSSuperListCell.h"
- #import "LDSuperListCell.h"
- #import "LDSearchCoupleWebViewController.h"
- #import "LDSuperListModel.h"
- #import "HCLoginViewController.h"
- #import <AlibabaAuthSDK/ALBBSession.h>
- #import "AccountTool.h"
- #import <AlibabaAuthSDK/ALBBSDK.h>
- @implementation FSSuperListCell
- -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self =[super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- CGRect collectionViewFrame= CGRectMake(0, 0,SCREEN_WIDTH, 400);
-
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
- // 每一行cell之间的间距
- flowLayout.minimumLineSpacing = FITSIZE(5);
- // // 每一列cell之间的间距
- flowLayout.minimumInteritemSpacing = FITSIZE(5);
- // // 设置第一个cell和最后一个cell,与父控件之间的间距
- flowLayout.sectionInset = UIEdgeInsetsMake(FITSIZE(10), FITSIZE(8),FITSIZE(10), FITSIZE(8));
- flowLayout.itemSize = CGSizeMake((SCREEN_WIDTH-FITSIZE(31))/4, (SCREEN_WIDTH-FITSIZE(31))/4);// 该行代码就算不写,item也会有默认尺寸
- UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:collectionViewFrame collectionViewLayout:flowLayout];
- collectionView.backgroundColor = [UIColor clearColor];
- collectionView.dataSource = self;
- collectionView.delegate = self;
- _collections = collectionView;
- _collections.showsVerticalScrollIndicator=NO;
- _collections.showsHorizontalScrollIndicator=NO;
- _collections.layer.masksToBounds=YES;
- _collections.scrollEnabled=NO;
- [self.collections registerClass:[LDSuperListCell class] forCellWithReuseIdentifier:@"cellId"];
- [self addSubview:_collections];
- }
- return self;
- }
- -(void)setArray:(NSArray *)array
- {
- _array = array;
- if (self.array.count %4 == 0) {
- self.collections.frame=CGRectMake(0, 0, SCREEN_WIDTH, (self.array.count/4)*((SCREEN_WIDTH-FITSIZE(31))/4+FITSIZE(10))) ;
- }else{
- self.collections.frame=CGRectMake(0, 0, SCREEN_WIDTH, (self.array.count/4+1)*((SCREEN_WIDTH-FITSIZE(31))/4+FITSIZE(10)));
- }
-
- [self.collections reloadData];
-
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
-
- return self.array.count;
- }
- - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
-
- LDSuperListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndexPath:indexPath];
- if (!cell ) {
-
- cell = [[LDSuperListCell alloc] init];
- }
- //品牌还在添加中。敬请期待。。
- cell.models=self.array[indexPath.row];
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- {
- LDSuperListModel *model= self.array[indexPath.row];
- //点击大牌商品
- LDSearchCoupleWebViewController *searchCoupleWeb = [[LDSearchCoupleWebViewController alloc] init];
- searchCoupleWeb.url = model.url;
- searchCoupleWeb.jsString = model.ios_js_string;
- searchCoupleWeb.name = model.name;
- if ([[ALBBSession sharedInstance] isLogin] && [AccountTool isLogin]) {
- //进入
- [[self currentViewController].navigationController pushViewController:searchCoupleWeb animated:YES];
- }else if (![AccountTool isLogin]) {
- //未登录
- HCLoginViewController *login = [[HCLoginViewController alloc] init];
- [[self currentViewController] presentViewController:login animated:YES completion:nil];
- }else if (![[ALBBSession sharedInstance] isLogin]) {
- //淘宝未授权
- ALBBSDK *albbSDK = [ALBBSDK sharedInstance];
- [albbSDK setAppkey:ALBC_APP_KEY];
- [albbSDK setAuthOption:NormalAuth];
- [albbSDK auth:[self currentViewController] successCallback:^(ALBBSession *session){
- [[NSNotificationCenter defaultCenter] postNotificationName:ChangeTaoBaoAuthor object:nil];
- [[self currentViewController].navigationController pushViewController:searchCoupleWeb animated:YES];
- } failureCallback:^(ALBBSession *session,NSError *error){
- NSLog(@"session == %@,error == %@",session,error);
- }];
- }
- }
- - (UIViewController *)currentViewController{
-
- UIViewController * currVC = nil;
- UIWindow *window = [UIApplication sharedApplication].delegate.window;
- UIViewController * Rootvc = window.rootViewController;
-
- do {
- if ([Rootvc isKindOfClass:[UINavigationController class]]) {
- UINavigationController * nav = (UINavigationController *)Rootvc;
- UIViewController * v = [nav.viewControllers lastObject];
- currVC = v;
- Rootvc = v.presentedViewController;
- continue;
- }else if([Rootvc isKindOfClass:[UITabBarController class]]){
- UITabBarController * tabVC = (UITabBarController *)Rootvc;
- currVC = tabVC;
- Rootvc = [tabVC.viewControllers objectAtIndex:tabVC.selectedIndex];
- continue;
- }
- } while (Rootvc!=nil);
-
- return currVC;
- }
- @end
|