123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687 |
- //
- // KXMainPageViewController.m
- // QBCS
- //
- // Created by kuxuan on 2017/6/6.
- // Copyright © 2017年 kuxuan. All rights reserved.
- //
- #import "KXMainPageViewController.h"
- #import "KXMainHorizontalCycleView.h"
- #import "KXCycleModel.h"
- #import "KXLoanButton.h"
- #import "KXMainListTableViewCell.h"
- #import "KXWebDetailViewController.h"
- #import "KXLoanAllDetailViewController.h"
- #import "KXLoanNewViewController.h"
- #import "KXMainDetailViewController.h"
- #import "KXLetterViewController.h"
- #import "KXMainDetailModel.h"
- #import "KXMainPageViewModel.h"
- #import "KXLoanAllModel.h"
- #import "KXDismissViewController.h"
- #import "KXMainVerticleCycleView.h"
- #import "KXVerticleModel.h"
- #import "KXMarkView.h"
- #import "KXThirdMarkView.h" //3.0的弹出框
- #import "KXBaseLinkViewController.h"
- #import "KXLaunchModel.h"
- #import <StoreKit/StoreKit.h>
- @interface KXMainPageViewController ()<KXMainHorizontalCycleDelegate,UITableViewDelegate,UITableViewDataSource,KXMainVerticleCycleViewDelegate,KXMarkViewDelegate,UINavigationControllerDelegate,KXThirdMarkViewDelegate>
- {
- KXMainHorizontalCycleView *_cycleView;
- KXMainVerticleCycleView *_verticleView;
- UIView *_headerView;
- UIView *_alertWindow;
- KXMarkView *_markView;
- KXLaunchModel *_launchModel;
- KXThirdMarkView *_thirdMarkView;
- }
- @property (nonatomic,strong)UITableView *tableView;
- @property (nonatomic,strong)NSMutableArray *dataSource;
- @property (nonatomic,assign)NSInteger page;
- @property (nonatomic,strong)UIButton *rightBtn;
- @property (nonatomic,strong)UILabel *redLabel;
- @property (nonatomic,strong)NSArray *otherSource; //新品区数据,暂时写死
- @property (nonatomic,strong)NSMutableArray *noticeArray; //公告数组
- @property (nonatomic,strong)NSMutableArray *allArray;
- @end
- @implementation KXMainPageViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.page=1;
- self.navigationController.delegate = self;
- [self setupUI];
- [self createTabletableView];
- [self setAdAlert];
- [self setNavgation];
- [self requestCycleViewData];
- [MobClick event:@"HomeTab"];
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
- // [self loadFirst];
- [self requestMoreLetterAction];
- }
- - (void)viewWillDisappear:(BOOL)animated
- {
- [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
- }
- - (void)setAdAlert
- {
- NSDate *date = [[NSUserDefaults standardUserDefaults]valueForKey:KXADALERTKEY];
-
- if (!date||[KXTime isToday:date]==NO) {
- _alertWindow = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
- _alertWindow.layer.cornerRadius = 8;
- _alertWindow.layer.masksToBounds = YES;
- _alertWindow.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
-
- UIImageView *adImageView = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2.0-150*SCREEN_MUTI, 106*SCREEN_MUTI, 300*SCREEN_MUTI, 430*SCREEN_MUTI)];
- [_alertWindow addSubview:adImageView];
- adImageView.userInteractionEnabled = YES;
- [KXMainPageViewModel getAdAlertUrl:^(KXLaunchModel *model) {
- _launchModel = model;
- [adImageView sd_setImageWithURL:[NSURL URLWithString:model.image_url]];
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(adClick:)];
- [adImageView addGestureRecognizer:tap];
- [self.view addSubview:_alertWindow];
- }];
-
- UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
- closeButton.frame = CGRectMake(SCREEN_WIDTH/2.0-15, 560*SCREEN_MUTI, 30, 30);
- [closeButton setImage:[UIImage imageNamed:@"main_alert_close"] forState:UIControlStateNormal];
- [closeButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
- [_alertWindow addSubview:closeButton];
-
- }
- NSDate *USDate = [NSDate date];
- NSTimeZone *zone = [NSTimeZone systemTimeZone];
- NSInteger seconds = [zone secondsFromGMTForDate:USDate];
- NSDate *nowDate = [USDate dateByAddingTimeInterval:seconds];
- [[NSUserDefaults standardUserDefaults]setValue:nowDate forKey:KXADALERTKEY];
- [[NSUserDefaults standardUserDefaults]synchronize];
-
- }
- - (void)closeAction
- {
- [MobClick event:@"advertisementHomeClose"];
- [_alertWindow.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- [obj removeFromSuperview];
- }];
- [_alertWindow removeFromSuperview];
- _alertWindow = nil;
- }
- - (void)adClick:(UITapGestureRecognizer *)tap
- {
- [MobClick event:@"advertisementHomeClick"];
- [_alertWindow.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- [obj removeFromSuperview];
- }];
- [_alertWindow removeFromSuperview];
- _alertWindow = nil;
-
- if ([_launchModel.skip_type isEqualToString:@"0"]) {
- if ([_launchModel.product_id isEqualToString:@"0"]) {
- KXBaseLinkViewController *baselink = [[KXBaseLinkViewController alloc]init];
- baselink.linkString = _launchModel.link;
- KXDismissViewController *detailNav=[[KXDismissViewController alloc]initWithRootViewController:baselink];
- [self.navigationController presentViewController:detailNav animated:YES completion:nil];
- }else{
- KXMainDetailViewController *detail=[[KXMainDetailViewController alloc]init];
- KXDismissViewController *detailNav=[[KXDismissViewController alloc]initWithRootViewController:detail];
- detail.detailID=_launchModel.product_id;
- detail.enterSource = @"homeAd";
- [self.navigationController presentViewController:detailNav animated:YES completion:nil];
-
- }
- }else{
- KXWebDetailViewController *web=[[KXWebDetailViewController alloc]init];
- KXDismissViewController *detailNav=[[KXDismissViewController alloc]initWithRootViewController:web];
- web.product_apply_id = @"0";
- web.product_id = _launchModel.product_id;
- web.webStr=_launchModel.link;
- [self.navigationController presentViewController:detailNav animated:YES completion:nil];
- }
- }
- -(void)requestMoreLetterAction
- {
- NSString *urlString=[NSString stringWithFormat:@"%@/news/getMaxIdSecond",URL];
- [KXHTTP post:urlString params:nil success:^(id json) {
- NSString *max=[[NSUserDefaults standardUserDefaults]objectForKey:MAX_ID];
- if (self.rightBtn) {
- if (!max||max.intValue<[json[@"max_id"] intValue]) {
- dispatch_async(dispatch_get_main_queue(), ^{
- self.redLabel.hidden=NO;
- });
-
- }else{
- dispatch_async(dispatch_get_main_queue(), ^{
- self.redLabel.hidden=YES;
- });
- }
- }
-
- } failure:^(NSError *error) {
-
- }];
- }
- -(void)setNavgation
- {
- self.rightBtn=[[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 30, 22, 20, 20)];
- [self.rightBtn setImage:[UIImage imageNamed:@"main_letter_white"] forState:UIControlStateNormal];
- [self.rightBtn addTarget:self action:@selector(letterAction) forControlEvents:UIControlEventTouchUpInside];
- [_headerView addSubview:self.rightBtn];
- [self.rightBtn setBadgeFrame:CGRectMake(14, 0, 6,6)];
- [self.rightBtn showBadge];
- }
- -(void)letterAction
- {
- [MobClick event:@"newsClick"];
- KXLetterViewController *letter=[[KXLetterViewController alloc]init];
- letter.hideblock = ^{
- [self.rightBtn clearBadge];
- };
- [self.navigationController pushViewController:letter animated:YES];
- }
- -(void)setupUI
- {
- _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 370*SCREEN_MUTI)];
- _headerView.backgroundColor=[UIColor KXColorWithHex:0xF4F4F4];
- // _headerView.layer.borderColor=[UIColor lineColor].CGColor;
- // _headerView.layer.borderWidth=0.3;
-
- _cycleView=[[KXMainHorizontalCycleView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 120*SCREEN_MUTI)];
- _cycleView.delegate=self;
- [_headerView addSubview:_cycleView];
-
- // UILabel *peapleLabel=[[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2-50, 22, 100, 20)];
- // peapleLabel.text=[NSString stringWithFormat:@"在线人数:%d人",15000+arc4random()%1000];
- // peapleLabel.textColor=[UIColor whiteColor];
- // peapleLabel.layer.cornerRadius=10;
- // peapleLabel.layer.masksToBounds=YES;
- // peapleLabel.font=FONT_SYS(10);
- // peapleLabel.textAlignment=NSTextAlignmentCenter;
- // peapleLabel.layer.borderColor=[UIColor whiteColor].CGColor;
- // peapleLabel.layer.borderWidth=1;
- // peapleLabel.backgroundColor=[UIColor colorWithWhite:0 alpha:0.6];
- // [_headerView addSubview:peapleLabel];
-
- _verticleView = [[KXMainVerticleCycleView alloc]initWithFrame:CGRectMake(0, 120*SCREEN_MUTI, SCREEN_WIDTH, 46*SCREEN_MUTI)];
- _verticleView.backgroundColor = [UIColor whiteColor];
- _verticleView.delegate = self;
- [_headerView addSubview:_verticleView];
- NSMutableArray *contentArray = [NSMutableArray arrayWithCapacity:0];
- [KXMainPageViewModel requestVerticleViewData:^(NSArray *notice) {
- for (KXVerticleModel *model in notice) {
- [self.noticeArray addObject:model];
- [contentArray addObject:model.content];
- }
- _verticleView.noticeArray = contentArray;
- }];
-
- CGFloat weight = (SCREEN_WIDTH-1)/2;
- CGFloat height = Fitsize(73);
- NSInteger rank = 2;
- //每列间距
- CGFloat rankMargin = (self.view.frame.size.width - rank * weight) / (rank - 1);
- //每行间距
- CGFloat rowMargin = 1;
- NSUInteger index = 4;
- for (int i=0; i<index; i++) {
- //Item X轴
- CGFloat X = (i % rank) * (weight + rankMargin);
- //Item Y轴
- NSUInteger Y = (i / rank) * (height +rowMargin);
- KXLoanButton *loanButton = [[KXLoanButton alloc]initWithFrame:CGRectMake(X, Fitsize(172)+Y, weight, height)];
- loanButton.redButton.hidden = YES;
- NSDictionary *dict = self.otherSource[i];
- loanButton.name = dict[@"title"];
- loanButton.tag = 555+i;
- loanButton.descName = dict[@"desc"];
- loanButton.buttonImage = [UIImage imageNamed:dict[@"image"]];
- [loanButton addTarget:self action:@selector(loanAction:) forControlEvents:UIControlEventTouchUpInside];
- [_headerView addSubview:loanButton];
- if (i==3) {
- [loanButton.redButton setTitle:@"new" forState:UIControlStateNormal];
- loanButton.redButton.hidden = NO;
- }
- [self setloanAllLabelName];
- }
-
- // UIImageView *hotImageView = [[UIImageView alloc]initWithFrame:CGRectMake(14, 228*SCREEN_MUTI, 18, 18)];
- // hotImageView.image = [UIImage imageNamed:@"main_hot"];
- // [_headerView addSubview:hotImageView];
-
- UIView *tabTopView = [[UIView alloc] initWithFrame:CGRectMake(0, Fitsize(324), SCREEN_WIDTH, 46)];
- tabTopView.backgroundColor = [UIColor whiteColor];
- [_headerView addSubview:tabTopView];
- UILabel *hotLabel=[[UILabel alloc]init];
- hotLabel.text=@"热门贷款平台";
- hotLabel.textColor=[UIColor titleColor];
- hotLabel.font=FONT_SYS(14*SCREEN_MUTI);
- [tabTopView addSubview:hotLabel];
-
- UIView *lineView = [[UIView alloc] init];
- lineView.backgroundColor = [UIColor KXColorWithHex:0xe5e5e5];
- [tabTopView addSubview:lineView];
-
- [hotLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(tabTopView.mas_left).offset(10);
- make.centerY.equalTo(tabTopView.mas_centerY);
- }];
- [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(tabTopView.mas_left).offset(10);
- make.bottom.equalTo(tabTopView.mas_bottom).offset(0);
- make.right.equalTo(tabTopView.mas_right).offset(-10);
- make.height.equalTo(@1);
- }];
-
- }
- - (void)loadFirst
- {
- BOOL mark = [[NSUserDefaults standardUserDefaults]boolForKey:@"mark"];
- if (mark == YES) {
- [self createMarkView];
- }
- [[NSUserDefaults standardUserDefaults]setBool:NO forKey:@"mark"];
- [[NSUserDefaults standardUserDefaults]synchronize];
- }
- - (void)markView:(NSNotification *)noti
- {
- [self createMarkView];
- }
- - (void)createMarkView
- {
- if (!_markView) {
- _markView = [[KXMarkView alloc]initWithFrame:[UIScreen mainScreen].bounds];
- _markView.delegate = self;
- [[UIApplication sharedApplication].keyWindow addSubview:_markView];
- }
-
- }
- - (void)createThirdMarkView{
- if (!_thirdMarkView) {
- _thirdMarkView = [[KXThirdMarkView alloc] initWithFrame:[UIScreen mainScreen].bounds];
- _thirdMarkView.delegate = self;
- [[UIApplication sharedApplication].keyWindow addSubview:_thirdMarkView];
- }
- }
- - (void)checkMarkView
- {
- NSDate *date = [[NSUserDefaults standardUserDefaults]objectForKey:KXMARK_TODAY];
- NSTimeInterval timeInterval = [[NSDate date] timeIntervalSinceDate:date];
- // 2.0的弹出框的处理逻辑
- // if (timeInterval > 3*24*60*60) {
- // [self createMarkView];
- // }
-
- // 3.0的处理逻辑
- NSInteger clickCount = [[NSUserDefaults standardUserDefaults] integerForKey:KXMARK_CLICKCOUNT];
- BOOL isMark = [[NSUserDefaults standardUserDefaults] boolForKey:KXMARK_TOAPPSTORE];
- if (isMark == YES) {
- if (timeInterval > 10*24*60*60) {
- if (clickCount >3 && clickCount%4 == 0) {
- [self createThirdMarkView];
- }
- }
- } else{
- if (!date) {
- if (clickCount >3 && clickCount%4==0) {
- [self createThirdMarkView];
- }
- }
- if (timeInterval > 3*24*60*60) {
- if (clickCount >3 && clickCount%4==0) {
- [self createThirdMarkView];
- }
- }
- }
- }
- #pragma mark ===================KXThirdMarkVIewDelegate==============
- - (void)markViewBtnClick:(UIButton *)button{
- switch (button.tag) {
- case 1000: //跳转按钮
- {
- [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:KXMARK_TODAY];
- [[NSUserDefaults standardUserDefaults] setBool:YES forKey:KXMARK_TOAPPSTORE];
- [[NSUserDefaults standardUserDefaults] synchronize];
- if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:KXAPPSTORE_ADDRESS]]) {
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:KXAPPSTORE_ADDRESS]];
- [_thirdMarkView removeFromSuperview];
- }
- }
- break;
- case 2000: //关闭按钮
- {
- [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:KXMARK_TODAY];
- [[NSUserDefaults standardUserDefaults] setBool:NO forKey:KXMARK_TOAPPSTORE];
- [[NSUserDefaults standardUserDefaults] synchronize];
- [_thirdMarkView removeFromSuperview];
- }
- break;
- default:
- break;
- }
- }
- #pragma mark =============KXMarkViewDelegate======================
- - (void)markViewSelectMarkItem:(NSInteger)index
- {
- switch (index) {
- case 0:{
- [[NSUserDefaults standardUserDefaults]setObject:[NSDate distantFuture] forKey:KXMARK_TODAY];
- [[NSUserDefaults standardUserDefaults]synchronize];
-
- [[UIApplication sharedApplication]openURL:[NSURL URLWithString:KXAPPSTORE_ADDRESS]];
-
- }
- break;
- case 1:{
- [[NSUserDefaults standardUserDefaults]setObject:[NSDate date] forKey:KXMARK_TODAY];
- [[NSUserDefaults standardUserDefaults]synchronize];
- }
- break;
- case 2:{
- [[NSUserDefaults standardUserDefaults]setObject:[NSDate distantFuture] forKey:KXMARK_TODAY];
- [[NSUserDefaults standardUserDefaults]synchronize];
- }
- break;
- default:
- break;
- }
- _markView = nil;
- }
- - (void)loanAction:(KXLoanButton *)btn
- {
- // if (btn.tag == 555) {
- // KXLoanNewViewController *new = [[KXLoanNewViewController alloc]init];
- // [self.navigationController pushViewController:new animated:YES];
- // }else{
- KXLoanAllModel *model = self.allArray[btn.tag - 555];
- NSArray *eventArr = @[@"speedKind",@"hotKind",@"largeKind",@"newKind"];
- [MobClick event:eventArr[btn.tag-555]];
- NSDictionary *dict = self.otherSource[btn.tag - 555];
- KXLoanAllDetailViewController *detail = [[KXLoanAllDetailViewController alloc]init];
- detail.changeLabel = ^{
- btn.redButton.hidden = YES;
- };
- detail.ID = [NSNumber numberWithInteger:model.Id.integerValue];
- detail.titleString = dict[@"title"];
- [self.navigationController pushViewController:detail animated:YES];
- }
- - (void)setloanAllLabelName
- {
- [KXMainPageViewModel loanAllLabelName:^(id json) {
- for (int i = 0; i < [json count]; i ++) {
- KXLoanAllModel *model = json[i];
- [self.allArray addObject:model];
- KXLoanButton *btn = [_headerView viewWithTag:556+i];
- if (model.label_name.length != 0) {
- btn.redButton.hidden = NO;
- [btn.redButton setTitle:model.label_name forState:UIControlStateNormal];
- }
- }
- }];
- }
- //请求轮播
- -(void)requestCycleViewData
- {
- NSString *urlString=[NSString stringWithFormat:@"%@/product/homeact",URL];
- [KXHTTP post:urlString params:@{@"version":@"2"} success:^(id json) {
- NSArray *array=[NSArray yy_modelArrayWithClass:[KXCycleModel class] json:json[@"homeact"]];
- _cycleView.scrollArray=array;
- } failure:^(NSError *error) {
-
- }];
- }
- -(void)clickScrollViewItemWithIndex:(NSInteger)index
- {
- [MobClick event:@"bannerClick"];
- KXCycleModel *model=_cycleView.scrollArray[index];
- if (model.link.length == 0) {
- KXMainDetailViewController *detail=[[KXMainDetailViewController alloc]init];
- detail.detailID=model.product_id.stringValue;
- detail.enterSource = @"banner";
- [self.navigationController pushViewController:detail animated:YES];
- }else{
- KXBaseLinkViewController *baseLink = [[KXBaseLinkViewController alloc]init];
- baseLink.linkString = model.link;
- [self.navigationController pushViewController:baseLink animated:YES];
- }
- }
- -(void)createTabletableView
- {
- self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-TabbarHeight) style:UITableViewStylePlain];
- if (@available(iOS 11.0, *)) {
- self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- }
- self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
- [self.tableView registerClass:[KXMainListTableViewCell class] forCellReuseIdentifier:@"main"];
- self.tableView.tableHeaderView = _headerView;
-
- //下拉刷新
- MJRefreshNormalHeader *header =
- [[MJRefreshNormalHeader alloc]init];
- header.arrowView.image = nil;
- [header setRefreshingTarget:self refreshingAction:@selector(refreshHeader:)];
- self.tableView.mj_header = header;
- [header beginRefreshing];
- //上拉加载
- MJRefreshAutoNormalFooter *footer=[[MJRefreshAutoNormalFooter alloc]init];
- [footer setRefreshingTarget:self refreshingAction:@selector(refreshFooter:)];
- self.tableView.mj_footer=footer;
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- [self.view addSubview:self.tableView];
-
- header.stateLabel.font = FONT_SYS(14);
- header.stateLabel.textColor=[UIColor detailTitleColor];
- header.lastUpdatedTimeLabel.font=FONT_SYS(14);
- header.lastUpdatedTimeLabel.textColor=[UIColor detailTitleColor];
- footer.stateLabel.textColor=[UIColor detailTitleColor];
- }
- #pragma mark 下拉刷新和上拉加载
- -(void)refreshHeader:(MJRefreshHeader *)header
- {
- self.page=1;
- [self requestSourceWithPage:self.page];
- }
- -(void)refreshFooter:(MJRefreshAutoFooter *)footer
- {
- self.page++;
- [self requestSourceWithPage:self.page];
- }
- -(void)requestSourceWithPage:(NSInteger)page
- {
- NSString *urlString=[NSString stringWithFormat:@"%@/product/searchSecond",URL];
- [KXHTTP post:urlString params:@{@"is_hot":@(YES),@"page":@(page)} success:^(id json) {
- NSArray *array=[NSArray yy_modelArrayWithClass:[KXHotList class] json:json[@"data"]];
- if (self.page==1) {
- [self.dataSource removeAllObjects];
- }
- for (KXHotList *model in array) {
- [self.dataSource addObject:model];
- }
- if (array.count < 10) {
- [_tableView.mj_header endRefreshing];
- [_tableView.mj_footer endRefreshing];
- [_tableView.mj_footer endRefreshingWithNoMoreData];
- }else{
- [_tableView.mj_header endRefreshing];
- [_tableView.mj_footer endRefreshing];
- }
- [_tableView reloadData];
- } failure:^(NSError *error) {
-
- }];
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.dataSource.count;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- KXHotList *model=self.dataSource[indexPath.row];
- KXMainListTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"main"];
- if (!cell) {
- cell=[[KXMainListTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"main"];
- }
- cell.selectionStyle=UITableViewCellSelectionStyleNone;
- // cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
- cell.hotmodel=model;
- return cell;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 87*SCREEN_MUTI;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- [MobClick event:@"homeListClick"];
- KXHotList *model=self.dataSource[indexPath.row];
- //0跳详情,1跳链接
- if ([model.skip_type isEqualToString:@"1"]) {
-
- KXWebDetailViewController *web=[[KXWebDetailViewController alloc]init];
- web.webStr=model.link;
- web.titleStr = model.name;
- web.product_id = model.Id;
- web.product_apply_id = @"0";
- [self.navigationController pushViewController:web animated:YES];
- }else{
- KXMainDetailViewController *detail=[[KXMainDetailViewController alloc]init];
- detail.detailID=model.Id;
- detail.titleString=model.name;
- detail.enterSource = @"hotList";
- [self.navigationController pushViewController:detail animated:YES];
- }
- }
- #pragma mark ------------------KXMainVerticleCycleViewDelegate------------------------
- - (void)clickmiddleViewWithIndex:(NSInteger)index
- {
- [MobClick event:@"noticeClick"];
- KXVerticleModel *model = self.noticeArray[index];
- if (!model.link) {
-
- }else{
- if ([model.skip_type isEqualToString:@"0"]) {
- if ([model.product_id isEqualToString:@"0"]) {
- KXBaseLinkViewController *baselink = [[KXBaseLinkViewController alloc]init];
- baselink.linkString = model.link;
- [self.navigationController pushViewController:baselink animated:YES];
- }else{
- KXMainDetailViewController *detail=[[KXMainDetailViewController alloc]init];
- detail.detailID=model.product_id;
- detail.enterSource = @"notice";
- [self.navigationController pushViewController:detail animated:YES];
- }
- }else{
- KXWebDetailViewController *web=[[KXWebDetailViewController alloc]init];
- web.product_apply_id = @"0";
- web.product_id = model.product_id;
- web.webStr=model.link;
- [self.navigationController pushViewController:web animated:YES];
- }
- }
- }
- #pragma mark - NAV的代理方法
- - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
- BOOL isShow = [viewController isKindOfClass:[self class]];
- [self.navigationController setNavigationBarHidden:isShow animated:YES];
- }
- -(NSMutableArray *)dataSource
- {
- if (!_dataSource) {
- _dataSource=[[NSMutableArray alloc]init];
- }
- return _dataSource;
- }
- -(NSArray *)otherSource
- {
- if (!_otherSource) {
- _otherSource=@[@{@"image":@"main_all_quick",@"title":@"极速贷",@"desc":@"最快2小时到账"},@{@"image":@"main_all_hot",@"title":@"热门贷",@"desc":@"大热贷款平台推荐"},@{@"image":@"main_all_stu",@"title":@"大额贷",@"desc":@"高额度 低门槛"},@{@"image":@"main_all_house",@"title":@"新品区",@"desc":@"最新上架平台"}];
- }
- return _otherSource;
- }
- - (NSMutableArray *)noticeArray
- {
- if (!_noticeArray) {
- _noticeArray = [NSMutableArray arrayWithCapacity:0];
- }
- return _noticeArray;
- }
- - (NSMutableArray *)allArray
- {
- if (!_allArray) {
- _allArray = [[NSMutableArray alloc]init];
- }
- return _allArray;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|