// // IfishDeviceViewController.m // ifishTabTest // // Created by imac on 16/7/25. // Copyright © 2016年 xiang. All rights reserved. // #import "IfishDeviceViewController.h" #import "TabbarDeiceSecdCell.h" #import "TabBarDeviceShouYeCell.h" #import "DXPopover.h" #import "LXPopView.h" #import "IfishBindDeviceSelectViewController.h" #import "IfishDataUnity.h" #import "IfishP2PMonitorController.h" #import "RightViewController.h" #import "UMComLoginDelegate.h" #import "UMComShowToast.h" #define UpdateUserProfileSuccess @"update user profile success!" #import "TabMineDeivceListViewCell.h" #import "UIImageView+WebCache.h" #import "FormatTankAddCamera.h" #import "IfishDataUnity.h" #import "IfishNewsModel.h" #import "PushMasssageWebViewController.h" #import "IfishP2PPlayBackListViewController.h" #import "ShuoMingShuCell.h" #import "UINavigationBar+Background.h" #import "IifshMineDJViewController.h" #import "QianDaoViewController.h" #import "IfishUserObsever.h" #import "IfishMineGoldViewController.h" #import "IfishUserDefaultHelper.h" #import "ShouYeAdViewCell.h" #import "IfishInformationViewController.h" #import "IfishAiLiShopGoodsViewCell.h" #import #import "IfishAlibcWebViewController.h" #import "MBProgressHUD.h" #import "RunSunChangeNameViewController.h" #import "IfishMessageViewController.h" #import "PushMessageModel.h" @interface IfishDeviceViewController () @property(nonatomic,strong)UITableView *tableView; @property(nonatomic,strong) NSArray *deviceArr; @property(nonatomic,strong) DXPopover *popover; @property(nonatomic,strong) NSArray *cameraArr; @property(nonatomic,strong) UIButton*rightButton; @property(nonatomic,strong) UIView *tabHeaderImgView; @property(nonatomic,strong) UIImageView *userImgView; @property(nonatomic,strong) UILabel *userNameLabel; @property(nonatomic,strong) UIButton *newsButton; @property(nonatomic,strong) UIView *newsRedPoint; @property(nonatomic,strong) UILabel *newsLabel; @property(nonatomic,strong) UIView *orangeView; @property(nonatomic,strong) UIButton *qianDaoBtn; @property(nonatomic,strong) UIView *qianDaoRedPoint; @property(nonatomic,strong) UIButton *goldBtn; @property(nonatomic,strong) UIButton *levelBtn; @property(nonatomic,strong) NSMutableArray *totalArr; @property(nonatomic,strong) IfishNewsModel *newsModel; @property (nonatomic) CGPoint inputPoint0; @property (nonatomic) CGPoint inputPoint1; @property (nonatomic) UIColor *inputColor0; @property (nonatomic) UIColor *inputColor1; @property (nonatomic) CGFloat scrollHeight; @property (nonatomic,strong) NSMutableArray *adViewData; @property (nonatomic,strong) NSMutableArray *goodsArr; @property (nonatomic,strong) MBProgressHUD *progressHud; @property (nonatomic,strong) UILabel *mesglabel; @property(nonatomic,assign)NSInteger curDeviceIdx; Assign NSInteger messageCount;//消息个数 //@property (nonatomic,strong) UIView *redView; @end @implementation IfishDeviceViewController - (void)viewDidLoad { [super viewDidLoad]; self.messageCount = 0; // Do any additional setup after loading the view. //self.view.backgroundColor = []; _adViewData = [[NSMutableArray alloc] init]; self.deviceArr = [[NSArray alloc] init]; self.cameraArr = [[NSArray alloc] init]; self.totalArr = [[NSMutableArray alloc] init]; _goodsArr= [[NSMutableArray alloc] init]; [self creatNav]; [self initUI]; [self showProgress]; [self addDataRequestQueue]; [self checkNotification]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deleteCurDevice) name:@"DeleteCurDevice" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateDevice) name:@"updateDevice" object:nil]; } -(void)updateDevice{ [self.tableView reloadData]; } -(void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self name:@"DeleteCurDevice" object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:@"updateDevice" object:nil]; } -(void)addDataRequestQueue { //创建异步任务队列 避免UI更新受影响 //串行异步队列 //dispatch_queue_t queue = dispatch_queue_create("com.privateQueue",NULL); dispatch_async(dispatch_get_main_queue(), ^{ [self getMoreUserData]; [self initBannerData]; [self loadGoodsData]; }); } -(void)showProgress{ self.progressHud = [[MBProgressHUD alloc] initWithView:[UIApplication sharedApplication].keyWindow]; self.progressHud.mode=MBProgressHUDModeCustomView; self.progressHud.customView = [[UIView alloc] init]; //self.progressHud.delegate = self; self.progressHud.labelText = @"加载中..."; } //app通过点击通知打开app,此处校验通知内容,做出相应的跳转 -(void)checkNotification{ //通过点击通知打开app,直接跳转到消息列表页面 if ([AppDelegate sharedDefault].remoteNotification) { IfishMessageViewController *message = [[IfishMessageViewController alloc]init]; UIViewController *vc= (UINavigationController *)[CommonUtils appRootViewController]; vc.hidesBottomBarWhenPushed = YES; [vc.navigationController pushViewController:message animated:YES]; vc.hidesBottomBarWhenPushed = NO; } } //获取未读消息个数 -(void)getMessageCount{ UserModel*userModel=[dataContorl getUserInfo]; NSDictionary *params = @{@"userId":userModel.userId }; [AFNOHeaderHttpTool requestWihtMethod:RequestTypePost url:Push_Message_UnReadCount params:params success:^(id response) { if (response) { id successDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil]; NSString *result = [successDic objectForKey:RESPONSE_CODE]; NSDictionary *dic = [successDic objectForKey:RESPONSE_DATA]; if ([result integerValue]==kReqSuccess) { NSString *count = [dic objectForKey:@"messageNoReadCount"]; self.messageCount = [count integerValue]; } [self setRedViewData]; } } failure:^(NSError *err) { }]; } #pragma mark - 首页广告位 -(void)initBannerData{ __weak typeof (self)weakSelf = self; [AFHttpTool getIfishBannerData:IfishAdTypeShouYE success:^(id response) { NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil]; NSString *result=reDic[@"result"]; if ([result isEqualToString:@"100"]) { NSArray *data= reDic[@"data"]; for (NSDictionary *dic in data) { IfishBannerData *bannerdata = [[IfishBannerData alloc] initWithDict:dic]; [self.adViewData addObject:bannerdata]; } NSIndexSet *asset = [NSIndexSet indexSetWithIndex:1]; [weakSelf.tableView reloadSections:asset withRowAnimation:UITableViewRowAnimationNone]; }else{ //[weakSelf.view makeToast:@"广告位获取失败"]; } } failure:^(NSError *err) { }]; } #pragma mark - 获取更多用户数据(新加) -(void)getMoreUserData{ NSString *userId = [dataContorl dataControlGetUserIdInfo]; __weak typeof (self)weakSelf = self; [AFHttpTool getMoreUserDataWith:userId success:^(id response) { NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil]; NSString *result=reDic[@"result"]; if ([result isEqualToString:@"100"]) { NSDictionary *dataDic = reDic[@"data"]; //资讯 information NSDictionary *informationdic=dataDic[@"information"]; if (informationdic) { IfishNewsModel *newsModel=[[IfishNewsModel alloc] initWithDict:informationdic]; [[DataCenter defaultDtacenter]setValue:newsModel forKey:@"informationNews"]; } //任务 NSArray*doneTaskArray=dataDic[@"goldTasks"]; if (!doneTaskArray) { doneTaskArray = [[NSArray alloc] init]; } NSMutableArray *taskArr = [[NSMutableArray alloc] init]; if (doneTaskArray.count!=0) { for (NSDictionary *taskDic in doneTaskArray) { IfishTaskModel *task = [[IfishTaskModel alloc] initWithDict:taskDic]; [taskArr addObject:task]; } } [[DataCenter defaultDtacenter]setValue:taskArr forKey:IFISHTASK_ARR]; //自己是商家 NSDictionary *shopsInfoDic=dataDic[@"shopsInfo"]; if (shopsInfoDic.count !=0) { //空时用的时候对象判空 CertificationShopModel *shopInfo=[[CertificationShopModel alloc] initWithDict:shopsInfoDic]; [[DataCenter defaultDtacenter]setValue:shopInfo forKey:@"ShopsInfo"]; }else{ CertificationShopModel *shopInfo=[[CertificationShopModel alloc] init]; [[DataCenter defaultDtacenter]setValue:shopInfo forKey:@"ShopsInfo"]; } //选择的商家信息 NSDictionary *kanHushopsInfoDic=dataDic[@"shopsInfo2"]; NSLog(@"kanHushopsInfoDic%lu",(unsigned long)kanHushopsInfoDic.count); if (kanHushopsInfoDic.count != 0) { //空时用的时候对象判空 CertificationShopModel *shopInfo2=[[CertificationShopModel alloc] initWithDict:kanHushopsInfoDic]; [[DataCenter defaultDtacenter]setValue:shopInfo2 forKey:@"ShopsInfo2"]; }else{ CertificationShopModel *shopInfo2=[[CertificationShopModel alloc] init]; [[DataCenter defaultDtacenter]setValue:shopInfo2 forKey:@"ShopsInfo2"]; } //设备信息 NSArray*deviceArray=dataDic[@"device"]; NSArray*cameraA=dataDic[@"camera"]; NSMutableArray *deviceArr = [[NSMutableArray alloc] init]; if ([deviceArray count]!=0) { for (NSDictionary*deviceDic in deviceArray) { DeviceModel*devicemodel=[[DeviceModel alloc] initWithDict:deviceDic]; [deviceArr insertObject:devicemodel atIndex:0]; } } [[DataCenter defaultDtacenter]setValue:deviceArr forKey:@"deviceInfo"]; //存储摄像头设备信息 NSMutableArray *camras = [[NSMutableArray alloc] init]; if (cameraA .count !=0) { if ([cameraA count]!=0) { for (NSDictionary * cameraDic in cameraA) { IfishCameraModel *camera=[[IfishCameraModel alloc] initWithDict:cameraDic]; [camras insertObject:camera atIndex:0]; } } } //存储摄像头数组 [[DataCenter defaultDtacenter]setValue:camras forKey:@"cameraArr"]; /** * 设备摄像头关系数组 */ NSArray*deviceCamera=dataDic[@"deviceCamera"]; NSMutableArray *devicamerArr=[[NSMutableArray alloc] init]; if (deviceCamera) { for (NSDictionary * deviceCameraDic in deviceCamera) { DeviceCameraModel *dcmodel=[[DeviceCameraModel alloc] init]; dcmodel.deviceId = deviceCameraDic[@"deviceId"]; dcmodel.cameraId = deviceCameraDic[@"cameraId"]; [devicamerArr addObject:dcmodel]; } } //存储摄像头设备关系数组 [[DataCenter defaultDtacenter]setValue:devicamerArr forKey:@"devicamerArr"]; [weakSelf refreshUI]; }else{ [weakSelf.view makeToast:@"户数据获取失败"]; } } failure:^(NSError *err) { [weakSelf.view makeToast:@"请求异常"]; }]; } -(UIView *)tabHeaderImgView{ //1776 if (!_tabHeaderImgView) { CGFloat headerH = TabContentHeaght *0.245 +64; _tabHeaderImgView = [[UIView alloc] init]; _tabHeaderImgView.frame = CGRectMake(0, 0, kScreenSize.width, headerH); //设置渐变色 _inputColor0 = RGB(10, 18, 177); _inputColor1 = RGB(50, 176, 239); _inputPoint0 = CGPointMake(0, 0); _inputPoint1 = CGPointMake(0, 1); CAGradientLayer *layer = [CAGradientLayer new]; layer.colors = @[(__bridge id)_inputColor0.CGColor, (__bridge id)_inputColor1.CGColor]; layer.startPoint = _inputPoint0; layer.endPoint = _inputPoint1; layer.frame = _tabHeaderImgView.bounds; [_tabHeaderImgView.layer addSublayer:layer]; } return _tabHeaderImgView; } -(UIImageView *)userImgView { if (!_userImgView) { CGFloat userImgViewW = TabContentHeaght*0.068; _userImgView =[[UIImageView alloc] init]; _userImgView.frame = CGRectMake(kScreenSize.width * 0.04, TabContentHeaght*0.04 +64, userImgViewW, userImgViewW); _userImgView.layer.masksToBounds = YES; _userImgView.layer.cornerRadius = userImgViewW * 0.5; } return _userImgView; } -(UILabel *)userNameLabel{ if (!_userNameLabel) { CGFloat nameH = 16*KWidth_Scale; _userNameLabel = [[UILabel alloc] init]; _userNameLabel.frame = CGRectMake(CGRectGetMaxX(_userImgView.frame) + 5 , CGRectGetMidY(_userImgView.frame)-nameH, kScreenSize.width -CGRectGetMaxX(_userImgView.frame) - 5 ,nameH); _userNameLabel.textAlignment = NSTextAlignmentLeft; _userNameLabel.textColor = [UIColor whiteColor]; //_userNameLabel.backgroundColor = [UIColor lightGrayColor]; } return _userNameLabel; } -(UIButton *)levelBtn { if (!_levelBtn) { _levelBtn = [UIButton buttonWithType:UIButtonTypeCustom]; //_levelBtn.backgroundColor = [UIColor redColor]; [_levelBtn setContentVerticalAlignment:UIControlContentVerticalAlignmentBottom]; [_levelBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft]; [_levelBtn addTarget:self action:@selector(levelBtnAction) forControlEvents:UIControlEventTouchUpInside]; } return _levelBtn; } -(UIButton*)qianDaoBtn{ if (!_qianDaoBtn) { CGFloat btnW = 67*KWidth_Scale; CGFloat btnH = btnW*0.36; CGFloat oriX = kScreenSize.width - CGRectGetMinX(_userImgView.frame); _qianDaoBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _qianDaoBtn.frame = CGRectMake(oriX - btnW,CGRectGetMinY(_userNameLabel.frame) ,btnW, btnH); [_qianDaoBtn setBackgroundImage:[UIImage imageNamed:@"home_iocn_signin"] forState:UIControlStateNormal]; [_qianDaoBtn addTarget:self action:@selector(qianDaoBtnAction) forControlEvents:UIControlEventTouchUpInside]; CGFloat pointW = 8; _qianDaoRedPoint = [[UIView alloc] initWithFrame:CGRectMake(pointW*KWidth_Scale,0, pointW , pointW )]; _qianDaoRedPoint.backgroundColor = RGB(252, 89, 89); _qianDaoRedPoint.layer.masksToBounds = YES; _qianDaoRedPoint.layer.cornerRadius = pointW /2; [_qianDaoBtn addSubview:self.qianDaoRedPoint]; } return _qianDaoBtn; } -(UIButton*)goldBtn{ if (!_goldBtn) { _goldBtn =[UIButton buttonWithType:UIButtonTypeCustom]; //_goldBtn.backgroundColor = [UIColor blueColor]; CGFloat btnH =40*KWidth_Scale; CGFloat btnW =100*KWidth_Scale; _goldBtn.frame = CGRectMake(CGRectGetMinX(_userNameLabel.frame), CGRectGetMaxY(_userNameLabel.frame)+6, btnW, btnH); [_goldBtn setTitleColor:RGB(252, 217, 94) forState:UIControlStateNormal]; _goldBtn.titleLabel.font = [UIFont systemFontOfSize:14]; [_goldBtn setImage:[UIImage imageNamed:@"home_iocn_gold"] forState:UIControlStateNormal]; [_goldBtn setImageEdgeInsets:UIEdgeInsetsMake(2,0, 0, 0)]; //[_goldBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,0, 0, 0)]; [_goldBtn setTitle:@"222" forState:UIControlStateNormal]; [_goldBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft]; [_goldBtn setContentVerticalAlignment:UIControlContentVerticalAlignmentTop]; [_goldBtn addTarget:self action:@selector(goldBtnAction:) forControlEvents:UIControlEventTouchUpInside]; } return _goldBtn; } -(void)getUsernameAddImg{ IfishUserAsset *userAsset = [dataContorl getAllIfishUserAsset]; UserModel*umodel=[dataContorl getUserInfo]; _userNameLabel.text = umodel.nickName; [_userNameLabel sizeToFit]; CGFloat btnH = 40*KWidth_Scale; CGFloat btnW =100*KWidth_Scale; _levelBtn.frame = CGRectMake(CGRectGetMaxX(_userNameLabel.frame) + 2, CGRectGetMaxY(_userNameLabel.frame) - btnH,btnW, btnH); NSString *title = [NSString stringWithFormat:@"LV%@",userAsset.gradeNum]; NSAttributedString * str= [[NSAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName:[UIFont fontWithName:@"Arial-BoldItalicMT" size:14],NSForegroundColorAttributeName:RGB(252, 217, 94)}]; [_levelBtn setAttributedTitle:str forState:UIControlStateNormal]; [_levelBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0,10)]; NSString *goldValue = [NSString stringWithFormat:@" 金币 %ld",(long)userAsset.goldValue]; [_goldBtn setTitle:goldValue forState:UIControlStateNormal]; if ([umodel.userImg isKindOfClass:[NSNull class]]) { [_userImgView setImage:[UIImage imageNamed:@"account"]]; }else if ([umodel.userImg isEqualToString:@""]){ // int i = (arc4random()%11) + 1;// 设置随机头像 // [self.backImg setImage:[UIImage imageNamed:[NSString stringWithFormat:@"acount%d.png",i]]]; //int i = (arc4random()%7) + 1;// 设置随机头像 int i = 1; [_userImgView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"userIcon%d.png",i]]]; }else{ NSLog(@"%@",[NSString stringWithFormat:@"%@%@",kGetIconUrl,umodel.userImg]); [_userImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kGetIconUrl,umodel.userImg]]]; } //资讯首页 IfishNewsModel *newsModel=[[DataCenter defaultDtacenter] valueForKey:@"informationNews"]; self.newsModel = newsModel; NSString *newsTitle= self.newsModel.title; _newsLabel.text =newsTitle; //签到按钮红点 _qianDaoRedPoint.hidden = userAsset.toDaySignin ? YES : NO; //资讯按钮红点 NSString *infoId =[IfishUserDefaultHelper getDefualtInfoId]; if (infoId) { if (infoId.intValue 0) { if(self.messageCount>=100){ _mesglabel.frame = RECT(self.mesglabel.frame.origin.x, self.mesglabel.frame.origin.y, 24, 16); } _mesglabel.text = [NSString stringWithFormat:@"%ld",(long)self.messageCount]; _mesglabel.hidden = NO; }else{ _mesglabel.text =@""; _mesglabel.hidden = YES; } } -(void)popAppear{ [self pushWiFiConnectVC]; } -(void)disSelectedPopViewIndex:(NSIndexPath *)Index{ [self.popover dismiss]; if (Index.row == 0) { self.hidesBottomBarWhenPushed = YES; RightViewController *rightVC=[[RightViewController alloc] init]; [self.navigationController pushViewController:rightVC animated:YES]; self.hidesBottomBarWhenPushed = NO; }else if (Index.row == 1){ [self pushWiFiConnectVC]; } } -(void)initUI{ self.automaticallyAdjustsScrollViewInsets = NO; [self.tableView registerNib:[UINib nibWithNibName:@"TabBarDeviceShouYeCell" bundle:nil] forCellReuseIdentifier:@"TabBarDeviceShouYeCell"]; [self.tableView registerNib:[UINib nibWithNibName:@"TabbarDeiceSecdCell" bundle:nil] forCellReuseIdentifier:@"TabbarDeiceSecdCell"]; //CGFloat sapce=TabContentHeaght*0.011;//20/1776 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.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.showsVerticalScrollIndicator = NO; self.tableView.backgroundColor = [UIColor whiteColor]; self.tableView.tableHeaderView = self.tabHeaderImgView; [self.tabHeaderImgView addSubview:self.userImgView]; [self.tabHeaderImgView addSubview:self.userNameLabel]; [self.tabHeaderImgView addSubview:self.orangeView]; [self.tabHeaderImgView addSubview:self.goldBtn]; [self.tabHeaderImgView addSubview:self.levelBtn]; [self.tabHeaderImgView addSubview:self.newsButton]; [self.tabHeaderImgView addSubview:self.newsLabel]; [self.tabHeaderImgView addSubview:self.qianDaoBtn]; self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; [self.view addSubview:self.tableView]; UILongPressGestureRecognizer *longpress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(addLongPressGesture:)]; [self.tableView addGestureRecognizer:longpress]; _scrollHeight = 64; if (@available(iOS 11.0, *)) { self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } } -(void)addLongPressGesture:(UILongPressGestureRecognizer *)guesture { if (guesture.state == UIGestureRecognizerStateBegan) { CGPoint point = [guesture locationInView:self.tableView]; NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point]; if (indexPath ==nil) return; if (indexPath.section!=0) return; UIAlertController*ac=[UIAlertController alertControllerWithTitle:@"" message:@"确定删除设备?" preferredStyle:UIAlertControllerStyleAlert]; [self presentViewController:ac animated:YES completion:nil]; [ac addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction*action){ }]]; [ac addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction*action){ [self removeDeviceAt:indexPath]; }]]; } } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; self.navigationController.navigationBar.translucent = YES; //设置透明导航栏 [self.navigationController.navigationBar setClearNav]; [self scrollViewDidScroll:self.tableView]; //内容置顶 //[self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; [self refreshUI]; //刷新消息数 [self setRedViewData]; [self getMessageCount]; } -(void)refreshUI{ self.deviceArr =[dataContorl getallDevices]; self.cameraArr =[dataContorl getallCameras]; [self getTotalDeviceArrWith:self.deviceArr addCameraArr:self.cameraArr]; [self.tableView reloadData]; [self getUsernameAddImg]; } -(void)getTotalDeviceArrWith:(NSArray *)deivceArr addCameraArr:(NSArray *)cameraArr; { if (self.totalArr.count !=0) { [self.totalArr removeAllObjects]; } for (DeviceModel *device in deivceArr) { FormatTankAddCamera *deviceListModel =[[FormatTankAddCamera alloc] init]; deviceListModel.device = device; deviceListModel.type = @"tank"; deviceListModel.deviceName = device.showName; deviceListModel.imgeaName = @"home_iocn_aquarium"; [self.totalArr addObject:deviceListModel]; } for (IfishCameraModel *camera in cameraArr) { FormatTankAddCamera *deviceListModel =[[FormatTankAddCamera alloc] init]; deviceListModel.camera = camera; deviceListModel.type = @"camera"; deviceListModel.deviceName = camera.showName; deviceListModel.imgeaName = @"home_iocn_camera"; [self.totalArr addObject:deviceListModel]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ //3个section 1headerView return 3; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if (section == 0) { NSInteger total = self.totalArr.count; return total ; } return 1; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ CGFloat listrowH=TabContentHeaght*0.074; if (indexPath.section ==2 &&indexPath.row ==0){ CGFloat Itemwidth = (kScreenSize.width-1)/2; CGFloat ItemH = Itemwidth*1.38 +1; if (_goodsArr.count!=0) { int total = (int)[_goodsArr count]; int rowCount =total%2==0?total/2:total/2+1; return ItemH*rowCount; } return ItemH*2; }else if (indexPath.section ==1){ CGFloat wH=kScreenSize.width*0.184; return wH; } return listrowH; } - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section== 0 ) { TabMineDeivceListViewCell *tCell=[tableView dequeueReusableCellWithIdentifier:@"TabMineDeivceListViewCell"]; if (tCell==nil) { tCell= [[[NSBundle mainBundle]loadNibNamed:@"TabMineDeivceListViewCell" owner:self options:nil]lastObject]; } [tCell setMineDeivceListData:self.totalArr AtIndexPath:indexPath ]; tCell.accessoryType=UITableViewCellAccessoryDisclosureIndicator; return tCell; }else if (indexPath.section== 2){ /*TabbarDeiceSecdCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TabbarDeiceSecdCell"]; if(cell==nil){ cell = [[TabbarDeiceSecdCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TabbarDeiceSecdCell"]; cell.backgroundColor = [UIColor whiteColor]; cell.selectionStyle = UITableViewCellSelectionStyleNone; }*/ static NSString *identfire=@"IfishAiLiShopGoodsViewCell"; IfishAiLiShopGoodsViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identfire]; if (!cell) { cell=[[IfishAiLiShopGoodsViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identfire]; } cell.delegate = self; [cell setGoodsdataArr:_goodsArr]; [cell refreshCollellction]; return cell; }else if (indexPath.section== 1){ ShouYeAdViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ShouYeAdViewCell"]; if(cell==nil){ cell = [[[NSBundle mainBundle]loadNibNamed:@"ShouYeAdViewCell" owner:self options:nil]lastObject]; cell.backgroundColor = [UIColor whiteColor]; } if (_adViewData.count !=0) { NSArray *ads =self.adViewData; NSMutableArray *imgs = [[NSMutableArray alloc] init]; [ads enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if ([obj isKindOfClass:[IfishBannerData class]]) { IfishBannerData *banner = (IfishBannerData *)obj; [imgs addObject:banner.adImage]; } }]; cell.adView.adList = imgs; __weak typeof (self)weakSelf = self; cell.adView.tapActionBlock =^(LXAdScrollView *adScrollView) { IfishBannerData *bdata = _adViewData[adScrollView.currentPage]; [weakSelf tapAdWithLink:bdata.adLink]; }; }else{ //默认加载本地 cell.adView.adList = @[@"Ifishbanner_shouye.jpg"]; cell.adView.tapActionBlock =^(LXAdScrollView *adScrollView) { }; } cell.adView.pageControl.hidden = YES; return cell; } else{ return nil; } } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ if (section == 0) { // CGFloat rowH=TabContentHeaght*0.088; return rowH; }else if (section == 2){ CGFloat remaiLabelH= TabContentHeaght * 0.074; return remaiLabelH; }else if (section == 1){ return 6; } return 0; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ if (section == 0) { // CGFloat rowH=TabContentHeaght*0.068; return rowH; }else if (section == 1){ return 4; }else if (section==2){ return 100; } return 0; } -(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ if (section == 0) { //我的设备view CGFloat rowH=TabContentHeaght*0.088; UIView *section0headerBackView =[[UIView alloc] initWithFrame:CGRectMake(0,0,kScreenSize.width, rowH)]; section0headerBackView.backgroundColor =RGB(50, 176, 239); UIView *section0header =[[UIView alloc] initWithFrame:CGRectMake(0,0,kScreenSize.width, rowH)]; section0header.backgroundColor = [UIColor whiteColor]; CGRect backRect= CGRectMake(0,0,kScreenSize.width,rowH); UIBezierPath *maskPath=[UIBezierPath bezierPathWithRoundedRect:backRect byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(15, 15)]; CAShapeLayer *maskLayer =[[CAShapeLayer alloc] init]; maskLayer.frame = backRect; maskLayer.path = maskPath.CGPath; section0header.layer.mask = maskLayer; [section0headerBackView addSubview:section0header]; CGFloat Space =kScreenSize.width*0.028; CGFloat hotW =kScreenSize.width*0.045; CGFloat ImgY= rowH - 10 -hotW; UIImageView *headImg =[[UIImageView alloc] initWithFrame:CGRectMake(Space, ImgY , hotW, hotW)]; headImg.image = [UIImage imageNamed:@"home_iocnmydevice"]; [section0header addSubview:headImg]; UILabel *mineLabel = [[UILabel alloc] init]; mineLabel.frame = CGRectMake(CGRectGetMaxX(headImg.frame) + Space,ImgY,100, hotW); mineLabel.text = @"我的设备"; mineLabel.textAlignment = NSTextAlignmentLeft; mineLabel.font = [UIFont systemFontOfSize:16]; //mineLabel.backgroundColor = [UIColor redColor]; [section0header addSubview:mineLabel]; UIButton *shuiMingBtn =[UIButton buttonWithType:UIButtonTypeCustom]; //shuiMingBtn.backgroundColor = [UIColor blueColor]; CGFloat btnW =200*KWidth_Scale; shuiMingBtn.frame = CGRectMake(kScreenSize.width -15 - btnW,0, btnW, rowH -10); [shuiMingBtn setTitleColor:RGB(0, 185.0, 239.0) forState:UIControlStateNormal]; shuiMingBtn.titleLabel.font = [UIFont systemFontOfSize:13]; UIImage *btnImg = [UIImage imageNamed:@"home_iocn_explorefastforward"]; [shuiMingBtn setImage:btnImg forState:UIControlStateNormal]; NSString *tilte = @"查看说明书"; CGSize size = [tilte sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13.0]}]; [shuiMingBtn setImageEdgeInsets:UIEdgeInsetsMake(-2,size.width,2,-size.width)]; [shuiMingBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,-btnImg.size.width -4, 0, btnImg.size.width+4)]; [shuiMingBtn setTitle:tilte forState:UIControlStateNormal]; [shuiMingBtn setContentVerticalAlignment:UIControlContentVerticalAlignmentBottom]; [shuiMingBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight]; [shuiMingBtn addTarget:self action:@selector(shuiMingBtnAction:) forControlEvents:UIControlEventTouchUpInside]; [section0header addSubview:shuiMingBtn]; [section0header bringSubviewToFront:shuiMingBtn]; UIView*lineview=[[UIView alloc] initWithFrame:CGRectMake(0,CGRectGetHeight(section0headerBackView.frame) -1, kScreenSize.width, 1)]; lineview.backgroundColor = [UIColor colorWithRed:221.0/255.0 green:221.0/255.0 blue:221.0/255.0 alpha:1]; [section0headerBackView addSubview:lineview]; [section0headerBackView bringSubviewToFront:lineview]; return section0headerBackView; }else if (section == 2){ //CGFloat seprwH=TabContentHeaght*0.011; CGFloat remaiLabelH= TabContentHeaght * 0.074; //UIView*header1view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,kScreenSize.width,seprwH + remaiLabelH)]; UIView*header1view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,kScreenSize.width, remaiLabelH)]; header1view.backgroundColor = [UIColor colorWithRed:242.0/255.0 green:242.0/255.0 blue:242.0/255.0 alpha:1]; CGFloat Space =kScreenSize.width*0.028; CGFloat hotW =kScreenSize.width*0.045; UIImageView *hotImgView=[[UIImageView alloc] init]; hotImgView.frame = CGRectMake(Space,remaiLabelH/2 - hotW/2 , hotW, hotW); hotImgView.image = [UIImage imageNamed:@"home_iocn_hotsell"]; CGFloat remaiLabelW = 70; UILabel *remaiLabel = [[UILabel alloc] init]; remaiLabel.frame = CGRectMake(CGRectGetMaxX(hotImgView.frame) + Space,0, remaiLabelW, remaiLabelH); remaiLabel.text = @"爱鱼严选"; remaiLabel.font = [UIFont systemFontOfSize:16]; remaiLabel.textAlignment = NSTextAlignmentLeft; //remaiLabel.backgroundColor = [UIColor redColor]; UILabel *yanxuanDetail = [[UILabel alloc] init]; yanxuanDetail.frame = CGRectMake(CGRectGetMaxX(remaiLabel.frame),0, 200, remaiLabelH); yanxuanDetail.text = @"爱鱼奇为您严格挑选的优质宝贝"; yanxuanDetail.font = [UIFont systemFontOfSize:11]; yanxuanDetail.textColor = RGB(153, 153, 153); UIView*backview=[[UIView alloc] initWithFrame:CGRectMake(0,0, kScreenSize.width,remaiLabelH)]; backview.backgroundColor = [UIColor whiteColor]; UIView*lineview=[[UIView alloc] initWithFrame:CGRectMake(0,CGRectGetHeight(backview.frame) -1, kScreenSize.width, 1)]; lineview.backgroundColor = [UIColor colorWithRed:221.0/255.0 green:221.0/255.0 blue:221.0/255.0 alpha:1]; [backview addSubview:lineview]; [backview addSubview:hotImgView]; [backview addSubview: remaiLabel]; [backview addSubview: yanxuanDetail]; [backview bringSubviewToFront:lineview]; [header1view addSubview:backview]; return header1view; }else if (section == 1){ UIView*view=[[UIView alloc] init]; view.backgroundColor = [UIColor whiteColor]; UIView*lineview=[[UIView alloc] initWithFrame:CGRectMake(0, 0,kScreenSize.width, 1)]; lineview.backgroundColor = RGB(242, 242, 242); [view addSubview:lineview]; return view; } return nil; } -(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ if (section == 0) { //添加设备view CGFloat rowH=TabContentHeaght*0.068; UIView*view=[[UIView alloc] initWithFrame:CGRectMake(0,0, kScreenSize.width, rowH)]; view.userInteractionEnabled = YES; view.backgroundColor = [UIColor whiteColor]; CGFloat Space =kScreenSize.width*0.063; CGFloat ImgW =kScreenSize.width*0.056; UIImageView *headImg =[[UIImageView alloc] initWithFrame:CGRectMake(Space,rowH/2 -ImgW/2 , ImgW, ImgW)]; headImg.image = [UIImage imageNamed:@"home_iocn_add"]; [view addSubview:headImg]; UIButton *addbtn =[UIButton buttonWithType:UIButtonTypeCustom]; CGFloat Space2 =kScreenSize.width*0.031; addbtn.frame = CGRectMake(CGRectGetMaxX(headImg.frame) + Space2 -3,1,200,rowH -2); [addbtn setTitleColor:RGB(153, 153, 153) forState:UIControlStateNormal]; [addbtn.titleLabel setFont:[UIFont systemFontOfSize:15]]; [addbtn setTitle:@"添加设备" forState:UIControlStateNormal]; addbtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [addbtn addTarget:self action:@selector(addBtnAction:) forControlEvents:UIControlEventTouchUpInside]; [view addSubview:addbtn]; return view; }else if (section == 1){ UIView *view = [[UIView alloc] init]; view.backgroundColor = RGB(242, 242, 242); return view; }else if (section ==2){ UIView *Footerback=[[UIView alloc] init]; Footerback.backgroundColor = RGB(242, 242, 242); return Footerback; } return nil; } #pragma mark- 添加设备 -(void)addBtnAction:(UIButton *)sender{ [self pushWiFiConnectVC]; } #pragma mark - qianDaoBtnAction -(void)qianDaoBtnAction{ QianDaoViewController *qiandaoVC= [[QianDaoViewController alloc] init]; self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:qiandaoVC animated:YES]; self.hidesBottomBarWhenPushed = NO; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; if (indexPath.section == 0) { if (self.totalArr.count==0) { return; } FormatTankAddCamera *model =self.totalArr[indexPath.row]; self.curDeviceIdx=indexPath.row; if (!model) { return; } if ([model.type isEqualToString:@"tank"]) { //切换时主动 断开 soket [[Socketsingleton sharedInstance] cutOffSocket]; [[IfishDataUnity shareDataInstance] initAppCenterVcWith:model.device addWithdissMisVc:nil]; }else if ([model.type isEqualToString:@"camera"]){ // self.hidesBottomBarWhenPushed = YES; // IfishP2PPlayBackListViewController *cameraShopVC=[[IfishP2PPlayBackListViewController alloc]init]; // cameraShopVC.camera = model.camera; // [self.navigationController pushViewController:cameraShopVC animated:YES]; // self.hidesBottomBarWhenPushed = NO; //切换时主动 断开 soket [[Socketsingleton sharedInstance] cutOffSocket]; //进入摄像头页面 IfishP2PMonitorController *p2pVC=[[IfishP2PMonitorController alloc] init]; p2pVC.contact = model.camera; UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:p2pVC]; UIApplication*app=[UIApplication sharedApplication]; AppDelegate*app1=(AppDelegate*)app.delegate; app1.window.rootViewController=nav; } }else if (indexPath.section == 2){ }else if (indexPath.section == 1) { } } #pragma mark - 设备使用说明 -(void)shuiMingBtnAction:(UIButton *)btn{ [self pushshuoMingView]; } -(void)pushshuoMingView{ self.hidesBottomBarWhenPushed = YES; PushMasssageWebViewController*webVC=[[PushMasssageWebViewController alloc]init]; webVC.pushlink =IFISH_DEVCEITROURL; //webVC.pushlink =@"http://q.eqxiu.com/s/KmmVl87l"; webVC.pushtitle = NSLocalizedString(@"ifish_deviceuse", nil); [self.navigationController pushViewController:webVC animated:YES]; self.hidesBottomBarWhenPushed = NO; } -(void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [self.view hideToastActivity]; self.navigationController.navigationBar.translucent = NO; [self.navigationController.navigationBar cnReset]; } #pragma mark 未绑定设备或添加设备 跳转 -(void)pushWiFiConnectVC{ IfishBindDeviceSelectViewController *connectVC=[[IfishBindDeviceSelectViewController alloc]init]; self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:connectVC animated:YES]; self.hidesBottomBarWhenPushed = NO; } #pragma mark - 长按删除 -(void)removeDeviceAt:(NSIndexPath*)indexPath; { FormatTankAddCamera *deviceListModel =self.totalArr[indexPath.row]; if ([deviceListModel.type isEqualToString:@"tank"]) { [self delectTankWith:deviceListModel AtIndexPath:indexPath]; }else{ //camera [self delectCamerWith:deviceListModel AtIndexPath:(NSIndexPath *)indexPath]; } } #pragma mark - 删除摄像头 -(void)delectCamerWith:(FormatTankAddCamera*)deviceListModel AtIndexPath:(NSIndexPath *)indexPath { AFHTTPRequestOperationManager*mannager=[AFHTTPRequestOperationManager manager]; mannager.responseSerializer=[AFHTTPResponseSerializer serializer]; NSMutableDictionary * para = [NSMutableDictionary dictionary]; // NSMutableArray*deviceIdArr=[[NSMutableArray alloc]init]; UserModel*model=[dataContorl getUserInfo]; IfishCameraModel *contact = deviceListModel.camera; NSString *cameraId=contact.cameraId; ; NSNumber *userId=model.userId; [para setValue:cameraId forKey:@"cameraId"]; [para setValue:userId forKey:@"userId"]; __weak typeof (self)weakSelf=self; [mannager POST:IfishdeleteCameraUser parameters:para success:^(AFHTTPRequestOperation *operation, id responseObject) { if (responseObject) { NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil]; if ([resultDic[@"result"] isEqualToString:@"100"]) { /** * 删除摄像头 前判断是否有 设备与其绑定关系 有解除关系 从关系数组中删除 */ NSMutableArray *guanxiiArr= [[DataCenter defaultDtacenter] valueForKey:@"devicamerArr"]; for (DeviceCameraModel *model in guanxiiArr) { if (contact.cameraId == model.cameraId ) { [guanxiiArr removeObject:model]; //保存新关系数组 [[DataCenter defaultDtacenter] setValue:guanxiiArr forKey:@"devicamerArr"]; } } NSArray*deviceArry=[[DataCenter defaultDtacenter]valueForKey:@"cameraArr"]; NSMutableArray *newArr = [NSMutableArray arrayWithArray:deviceArry]; //重置数据库 for (IfishCameraModel *model in deviceArry) { if ([model.cameraId isEqual:contact.cameraId]) { [newArr removeObject:model]; } } [[DataCenter defaultDtacenter] setValue: newArr forKey:@"cameraArr"]; [weakSelf.totalArr removeObjectAtIndex:indexPath.row]; [weakSelf.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self.tableView reloadData]; //[self.tableView reloadSections:[[NSIndexSet alloc] initWithIndex:0] withRowAnimation: UITableViewRowAnimationFade]; }); [weakSelf.view makeToast:@"删除成功"]; }else if ([resultDic[@"result"] isEqualToString:@"101"]){ [weakSelf.view makeToast:@"删除失败"]; }else if ([resultDic[@"result"] isEqualToString:@"301"]){ [weakSelf.view makeToast:@"请求验证失败,请重新登陆"]; }else if ([resultDic[@"result"] isEqualToString:@"302"]){ [weakSelf.view makeToast:@"请求被舍弃,未执行"]; } } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { [weakSelf.view makeToast:@"请求异常"]; }]; } #pragma mark - 删除设备 -(void)delectTankWith:(FormatTankAddCamera*)deviceListModel AtIndexPath:(NSIndexPath *)indexPath { AFHTTPRequestOperationManager*mannager=[AFHTTPRequestOperationManager manager]; mannager.responseSerializer=[AFHTTPResponseSerializer serializer]; NSMutableDictionary * para = [NSMutableDictionary dictionary]; NSString *priId=deviceListModel.device.deviceId; ; NSString*userId=deviceListModel.device.userId; [para setValue:priId forKey:@"priId.deviceId"]; [para setValue:userId forKey:@"priId.userId"]; __weak typeof (self)weakSelf=self; [mannager POST:kDeleteDeviceUser parameters:para success:^(AFHTTPRequestOperation *operation, id responseObject) { if (responseObject) { NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil]; if ([resultDic[@"result"] isEqualToString:@"100"]) { NSMutableArray *guanxiiArr= [[DataCenter defaultDtacenter] valueForKey:@"devicamerArr"]; for (DeviceCameraModel *model in guanxiiArr) { if (deviceListModel.device.deviceId == model.deviceId ) { [guanxiiArr removeObject:model]; //保存新关系数组 [[DataCenter defaultDtacenter] setValue:guanxiiArr forKey:@"devicamerArr"]; } } //重置数据 NSArray*deviceArry=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"]; NSMutableArray *newArr = [NSMutableArray arrayWithArray:deviceArry]; for (DeviceModel *model in deviceArry) { if ([model.deviceId isEqual:deviceListModel.device.deviceId]) { [newArr removeObject:model]; } } [[DataCenter defaultDtacenter] setValue: newArr forKey:@"deviceInfo"]; [weakSelf.totalArr removeObjectAtIndex:indexPath.row]; [weakSelf.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight]; //GCD中的dispatch_after 实现单次的延时调用 dispatch_time的单位是纳秒,为防止用户使用时候的出现换算上的错误,Xcode在开发者打dispatch_after的时候会自动补全下面一整段代码 //dispatch_after是延迟提交,不是延迟运行 //NSEC:纳秒。 //USEC:微妙。 //SEC:秒 //PER:每 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadData]; }); /* 而如果有循环的调用的话,可以用dispatch_source_set_timer来实现 用到GCD的事件源和事件监听的机制 int interval = 2; int leeway = 0; dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); if (timer) { dispatch_source_set_timer(timer, dispatch_walltime(DISPATCH_TIME_NOW, NSEC_PER_SEC * interval), interval * NSEC_PER_SEC, leeway); dispatch_source_set_event_handler(timer, ^{ [self someMethod]; }); dispatch_resume(timer); } */ [weakSelf.view makeToast:@"删除成功"]; }else if ([resultDic[@"result"] isEqualToString:@"101"]){ [weakSelf.view makeToast:@"删除失败"]; }else if ([resultDic[@"result"] isEqualToString:@"301"]){ [weakSelf.view makeToast:@"请求验证失败,请重新登陆"]; }else if ([resultDic[@"result"] isEqualToString:@"302"]){ [weakSelf.view makeToast:@"请求被舍弃,未执行"]; } } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { [weakSelf.view makeToast:@"请求异常"]; }]; } #pragma mark---删除当前缓存设备 -(void)deleteCurDevice{ FormatTankAddCamera *deviceListModel =self.totalArr[self.curDeviceIdx]; NSMutableArray *guanxiiArr= [[DataCenter defaultDtacenter] valueForKey:@"devicamerArr"]; for (DeviceCameraModel *model in guanxiiArr) { if (deviceListModel.device.deviceId == model.deviceId ) { [guanxiiArr removeObject:model]; //保存新关系数组 [[DataCenter defaultDtacenter] setValue:guanxiiArr forKey:@"devicamerArr"]; } } //重置数据 NSArray*deviceArry=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"]; NSMutableArray *newArr = [NSMutableArray arrayWithArray:deviceArry]; for (DeviceModel *model in deviceArry) { if ([model.deviceId isEqual:deviceListModel.device.deviceId]) { [newArr removeObject:model]; } } [[DataCenter defaultDtacenter] setValue: newArr forKey:@"deviceInfo"]; [self.totalArr removeObjectAtIndex:self.curDeviceIdx]; NSIndexPath*indexPath=[NSIndexPath indexPathForRow:self.curDeviceIdx inSection:0]; [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight]; //GCD中的dispatch_after 实现单次的延时调用 dispatch_time的单位是纳秒,为防止用户使用时候的出现换算上的错误,Xcode在开发者打dispatch_after的时候会自动补全下面一整段代码 //dispatch_after是延迟提交,不是延迟运行 //NSEC:纳秒。 //USEC:微妙。 //SEC:秒 //PER:每 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self.tableView reloadData]; }); } #pragma mark - 商品列表加载 -(void)loadGoodsData{ __weak typeof (self)weskSelf=self; [AFHttpTool getIfishGoodsListWith:IfishGoodsTypeShouYE success:^(id response) { NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil]; if ([reDic[@"result"] isEqualToString:@"100"]){ NSLog(@"商品列表加载100"); NSArray*goodsArr=reDic[@"data"]; for (NSDictionary *goodsDic in goodsArr) { IfishGoodsData *goodsData=[[IfishGoodsData alloc] initWithDict:goodsDic]; [weskSelf.goodsArr addObject:goodsData]; } NSIndexSet *asset = [NSIndexSet indexSetWithIndex:2]; [weskSelf.tableView reloadSections:asset withRowAnimation:UITableViewRowAnimationNone]; } [weskSelf.progressHud hide:YES]; } failure:^(NSError *err) { [weskSelf.progressHud hide:YES]; NSLog(@"%@errrrrr",err); }]; } #pragma mark UIScrollViewDelegate - (void)scrollViewDidScroll:(UIScrollView *)scrollView { UIColor *color = [UIColor colorWithRed:53/255.0 green:53/255.0 blue:53/255.0 alpha:1]; CGFloat offsetY = scrollView.contentOffset.y; //NSLog(@"offsetY:%f",offsetY); if (offsetY > 0) { CGFloat alpha = MIN(1, (offsetY)/_scrollHeight); [self.navigationController.navigationBar cnSetBackgroundColor:[color colorWithAlphaComponent:alpha]]; self.tableView.backgroundColor = [UIColor whiteColor]; } else { //下拉 [self.navigationController.navigationBar cnSetBackgroundColor:[color colorWithAlphaComponent:0]]; //CGRect rect = self.tabDowloadHoldView.frame; ////我们只需要改变图片的y值和高度即可 //rect.size.height = - offsetY; //self.tabDowloadHoldView.frame = rect; self.tableView.backgroundColor = RGB(10, 18, 177); } } #pragma mark - 我的等级 -(void)levelBtnAction{ IifshMineDJViewController *mineLevelVC = [[IifshMineDJViewController alloc] init]; self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:mineLevelVC animated:YES]; self.hidesBottomBarWhenPushed = NO; } #pragma mark - 我的金币 -(void)goldBtnAction:(UIButton*)btn{ IfishMineGoldViewController *GoldViewVC = [[IfishMineGoldViewController alloc] init]; self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:GoldViewVC animated:YES]; self.hidesBottomBarWhenPushed = NO; } #pragma mark - 广告点击事件 -(void)tapAdWithLink:(NSString *)pushLink { if (![pushLink isKindOfClass:[NSNull class]] &&pushLink &&![pushLink isEqualToString:@""]){ //字条串是否包含有某字符串 if ([pushLink rangeOfString:@"taobao"].location == NSNotFound) { self.hidesBottomBarWhenPushed = YES; PushMasssageWebViewController*webVC=[[PushMasssageWebViewController alloc]init]; webVC.pushlink =pushLink; webVC.pushtitle = @"详情"; [self.navigationController pushViewController:webVC animated:YES]; self.hidesBottomBarWhenPushed = NO; } else { [self openAliBCWithLink:pushLink]; } } } #pragma mark - 商品列表点击事件 // 宝贝详情页面 -(void)tapTtemListAt:(NSString *)goodslink { [self openAliBCWithLink:goodslink]; } -(void)openAliBCWithLink:(NSString *)linkUrl{ //查看商品 加金币 [[IfishUserObsever sharedInstance] addGoldWith:OPENGOODSLINK addType:IFISHADDGOLDTYPE0]; //535991514644 //根据商品ID //id page = [AlibcTradePageFactory itemDetailPage: @"535991514644"]; //根据链接打开页面 id page = [AlibcTradePageFactory page:linkUrl]; AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init]; //app 内闭环交易 强制H5 打开 showParam.openType = AlibcOpenTypeH5; //AlibcWebViewController* myView = [[AlibcWebViewController alloc] init]; //自定义web IfishAlibcWebViewController* myView = [[IfishAlibcWebViewController alloc] init]; NSInteger ret = [[AlibcTradeSDK sharedInstance].tradeService show:self.navigationController webView:myView.webView page:page showParams:showParam taoKeParams:nil trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) { } tradeProcessFailedCallback:^(NSError * _Nullable error) { }]; //返回1,说明h5打开,否则不应该展示页面 if (ret == 1) { self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:myView animated:YES]; self.hidesBottomBarWhenPushed = NO; } } #pragma mark - 导航栏消息,跳转进入消息列表 -(void)navMeaasageBtnAction{ self.messageCount = 0; [self setRedViewData];//刷新消息显示 // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:sessionList]; // [nav.navigationBar resetBackgroundImage]; // nav.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; // [self presentViewController:nav animated:YES completion:nil]; IfishMessageViewController *message = [[IfishMessageViewController alloc]init]; self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:message animated:YES]; self.hidesBottomBarWhenPushed = NO; } @end