// // ZBHotGoodVC.m // ZBProject // // Created by 学丽 on 2019/4/9. // Copyright © 2019 ZB. All rights reserved. // #import "ZBHotGoodVC.h" @interface ZBHotGoodVC () @property(nonatomic,strong)UITableView *tableViews; @property(nonatomic,strong)NSMutableArray *carArray; @property(nonatomic,strong)ZBTableHeadView *headView; @end @implementation ZBHotGoodVC - (void)viewDidLoad { [super viewDidLoad]; [self initWithNav]; [self getCartgood]; } -(void)updateHotGoodData { } -(void)getCartgood { if (![AccountTool isLogin]) { return; } [LoadingView showInView:self.view]; [ZBHTTP post:getCarListURL params:nil success:^(id _Nonnull json) { self.headView.titlelabel.text=[NSString stringWithFormat:@"共%@件商品",json[@"count"]]; NSArray *array =[NSArray yy_modelArrayWithClass:[ZBGoodModel class] json:json[@"data"]]; [self.carArray addObjectsFromArray:array]; if (self.carArray.count==0) { [self setUpNoDataView]; } [self.tableViews reloadData]; [LoadingView dismiss]; } failure:^(NSError * _Nonnull error) { [LoadingView dismiss]; }]; } -(void)initWithNav { //接收通知,侧滑的时候 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(updateHotGoodData) name:@"hotorder" object:nil]; //添加tableview [self.view addSubview:self.tableViews]; [self.tableViews mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.height.mas_equalTo(SCREEN_HEIGHT-45-NavBarHeight); make.left.right.mas_equalTo(0); }]; self.headView=[[ZBTableHeadView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)]; self.tableViews.tableHeaderView=self.headView; } #pragma mark---TableViewDelegate&&DataSource -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ZBShopCarListCell *listC =[tableView dequeueReusableCellWithIdentifier:@"list"]; if (!listC) { listC=[[ZBShopCarListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"list"]; listC.selectionStyle=UITableViewCellSelectionStyleNone; } listC.model=self.carArray[indexPath.section]; return listC; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return self.carArray.count; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 122; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 0.00; } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *back =[[UIView alloc]init]; back.backgroundColor=[UIColor YHColorWithHex:0xF4F4F4]; return back; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { } -(UITableView *)tableViews { if (!_tableViews) { _tableViews =[[UITableView alloc]init]; _tableViews.delegate=self; _tableViews.dataSource=self; _tableViews.backgroundColor=[UIColor whiteColor]; _tableViews.separatorStyle=UITableViewCellSeparatorStyleNone; // _tableViews.layer.cornerRadius=10; // _tableViews.layer.masksToBounds=YES; _tableViews.showsHorizontalScrollIndicator=NO; _tableViews.showsVerticalScrollIndicator=NO; } return _tableViews; } -(NSMutableArray *)carArray { if (!_carArray) { _carArray =[NSMutableArray array]; } return _carArray; } #pragma mark -- 移除通知 -(void)dealloc{ [[NSNotificationCenter defaultCenter]removeObserver:self]; } - (void)setUpNoDataView { self.tableViews.showNoDataView = YES; self.tableViews.noDataImageOffsetY = -70; self.tableViews.defaultNoDataText = @"还没有记录"; self.tableViews.defaultNoDataImage = [UIImage imageNamed:@"no_order"]; } @end