// // IfishGoldCoastViewController.m // Ifish // // Created by imac on 2017/4/25. // Copyright © 2017年 lianlian. All rights reserved. // #import "IfishGoldCoastViewController.h" #import "GolaCoastListViewCell.h" #import "CoastRecordViewController.h" #import "IfishGoldCoastDetailViewController.h" #import "DiscountCoupon.h" @interface IfishGoldCoastViewController () @property(nonatomic,strong)UITableView *tableView; @property(nonatomic,strong)NSMutableArray *dataArr; @property (nonatomic) NSIndexPath *selectIndexPath; @property (nonatomic) BOOL isChage; @end @implementation IfishGoldCoastViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self addTitleViewWithTitle:@"金币兑换"]; _dataArr =[[NSMutableArray alloc] init]; _isChage = NO; [self creatTab]; UIBarButtonItem*rightItem= [[UIBarButtonItem alloc] initWithTitle:@"兑换记录" style:UIBarButtonItemStyleDone target:self action:@selector(duihuanjiluAction)]; self.navigationItem.rightBarButtonItem= rightItem; [self.navigationItem.rightBarButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14],NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal]; [self loadDataS]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(quanChangeDidChange:) name:@"quanChange" object:nil]; } -(void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self name:@"quanChange" object:nil]; } -(void)quanChangeDidChange:(NSNotification *)noty{ DiscountCoupon *model=[noty object]; _isChage = YES; [self.dataArr replaceObjectAtIndex:self.selectIndexPath.section withObject:model]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; if (_isChage ) { [self.tableView reloadData]; } } -(void)creatTab{ self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height) style:UITableViewStyleGrouped]; self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.scrollEnabled = YES; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.showsVerticalScrollIndicator = NO; self.tableView.backgroundColor = RGB(242, 242, 242); [self.view addSubview:self.tableView]; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return _dataArr.count; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 1; } -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ GolaCoastListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GolaCoastListViewCell"]; if (!cell) { cell = [[[NSBundle mainBundle]loadNibNamed:@"GolaCoastListViewCell" owner:self options:nil]lastObject]; } DiscountCoupon *model = _dataArr[indexPath.section]; [cell loadCellwith:model]; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 130; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 0.1; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 0.1; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ _selectIndexPath = indexPath; IfishGoldCoastDetailViewController *detail = [[IfishGoldCoastDetailViewController alloc] init]; self.hidesBottomBarWhenPushed = YES; detail.convert = _dataArr[indexPath.section]; [self.navigationController pushViewController:detail animated:YES]; } -(void)loadDataS{ __weak typeof (self)weakSelf = self; [AFHttpTool getValidatingCouponsSuccess:^(id response) { NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil]; NSString *result=reDic[@"result"]; NSLog(@"redic***:%@",reDic); if ([result isEqualToString:@"100"]){ NSArray *dataArr =reDic[@"data"]; for (NSDictionary *dic in dataArr) { DiscountCoupon *model = [[DiscountCoupon alloc] initWithDict:dic]; [_dataArr addObject:model]; } [weakSelf.tableView reloadData]; }else{ [weakSelf.view makeToast:@"请求异常"]; } } failure:^(NSError *err) { [weakSelf.view makeToast:@"请求异常"]; }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - 兑换记录 -(void)duihuanjiluAction { CoastRecordViewController *recordVC= [[CoastRecordViewController alloc] init]; self.hidesBottomBarWhenPushed = YES; recordVC.fromDetailVC = NO; [self.navigationController pushViewController:recordVC animated:YES]; } /* #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