// // YooseeCenterViewController.m // Ifish // // Created by imac on 16/6/28. // Copyright © 2016年 lianxiang. All rights reserved. // #import "YooseeCenterViewController.h" #import "YooseeCenterViewCell.h" #import "FListManager.h" #import "Utils.h" #import "IfishP2PMonitorController.h" #import "ScanViewController.h" @interface YooseeCenterViewController () @property(nonatomic,strong)UITableView *tableView; @property(nonatomic,strong)UIButton *openDrawerButton; @property(nonatomic,strong)NSMutableArray *yooseeDeviceArr; @end @implementation YooseeCenterViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //这里本想展示摄像头列表已改之只展示选中摄像头 self.yooseeDeviceArr = [[NSMutableArray alloc] init]; [self initUI]; } -(void)viewWillAppear:(BOOL)animated{ [AppDelegate sharedDefault].canFullScreen = NO; } -(void)viewDidAppear:(BOOL)animated{ self.yooseeDeviceArr = [[DataCenter defaultDtacenter] valueForKey:@"cameraArr"]; for (IfishCameraModel *camera in self.yooseeDeviceArr) { if ([camera.cameraId isEqualToString:self.cameraModel.cameraId]) { self.cameraModel = camera; } } [self.tableView reloadData]; } -(void)initUI{ UINavigationBar *nav=[[UINavigationBar alloc] init]; nav.frame = CGRectMake(0, 0, kScreenSize.width, 64); [nav setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; [self.view addSubview:nav]; UIImage *hamburger = [UIImage imageNamed:@"ifishmenu"]; self.openDrawerButton = [UIButton buttonWithType:UIButtonTypeCustom]; self.openDrawerButton.frame = CGRectMake(0.0f, 20.0f, 47,44); [self.openDrawerButton setImage:hamburger forState:UIControlStateNormal]; [self.openDrawerButton addTarget:self action:@selector(openDrawer:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:self.openDrawerButton]; //标题 UILabel*name=[[UILabel alloc]initWithFrame:CGRectMake(kScreenSize.width/2-30,13,120, 60)]; name.text=@"爱鱼奇"; name.textColor=[UIColor whiteColor]; // name.adjustsFontSizeToFitWidth=YES; name.font=[UIFont systemFontOfSize:20]; [self.view addSubview:name]; self.view.backgroundColor=COLOR_MIAN; UIImage*MyEquipmentImage=[UIImage imageNamed:@"ifisharrow_r"]; UIButton*MyEquipmentButton=[UIButton buttonWithType:UIButtonTypeCustom] ; [MyEquipmentButton setImage:MyEquipmentImage forState:UIControlStateNormal]; MyEquipmentButton.frame=CGRectMake(kScreenSize.width-47, 20, 47,44); [MyEquipmentButton addTarget:self action:@selector(MyepClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:MyEquipmentButton]; [self.tableView registerNib:[UINib nibWithNibName:@"YooseeCenterViewCell" bundle:nil] forCellReuseIdentifier:@"YooseeCenterViewCell"]; self.tableView = [[UITableView alloc] init]; self.tableView.frame = CGRectMake(0, 64, kScreenSize.width, kScreenSize.height - 64); self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.backgroundColor = COLOR_MIAN; [self.view addSubview:self.tableView]; } //此方法已去 - (void)openDrawer:(id)sender { dispatch_async(dispatch_get_main_queue(), ^{ [self.drawer openLeft]; }); } -(void)MyepClick{ [self.drawer openRight]; } - (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. } */ #pragma mark - ICSDrawerControllerPresenting #pragma mark center 主界面抽屉代理方法 - (void)drawerControllerWillOpen:(ICSDrawerController *)drawerController { self.view.userInteractionEnabled = NO; } - (void)drawerControllerDidClose:(ICSDrawerController *)drawerController { self.view.userInteractionEnabled = YES; } #pragma mark -表格 //多少段 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ // if([self.yooseeDeviceArr count]<=0){ // //[self.emptyView setHidden:NO]; // [self.tableView setScrollEnabled:NO]; // }else{ // //[self.emptyView setHidden:YES]; // [self.tableView setScrollEnabled:YES]; // } // return [self.yooseeDeviceArr count]; return 1; } //每段多少行 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 1; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return kScreenSize.width * 0.56; } //section的高度 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 0.0; //我很想保留10像素header呵呵 } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ UIView *headerView = [[UIView alloc] init]; //[headerView setBackgroundColor:XBGAlpha]; [headerView setBackgroundColor:[UIColor lightGrayColor]]; [tableView setTableHeaderView:headerView]; return headerView; } - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { cell.backgroundColor = [UIColor clearColor]; //自定义cell的背景 UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, cell.frame.size.width, cell.frame.size.height)]; backgroundView.backgroundColor = XWhite; //导航的底线 } - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ YooseeCenterViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YooseeCenterViewCell"]; if(cell==nil){ cell = [[[NSBundle mainBundle]loadNibNamed:@"YooseeCenterViewCell" owner:self options:nil]lastObject]; } //self.cameraModel= [self.yooseeDeviceArr objectAtIndex:indexPath.section]; NSString *filePath = [Utils getHeaderFilePathWithId:self.cameraModel.cameraId]; UIImage *headImg = [UIImage imageWithContentsOfFile:filePath]; if(headImg==nil){ cell.yooseholdImg.image = LXImageWithImageName(@"ic_header.png"); }else{ cell.yooseholdImg.image = headImg; } cell.startImg.image = LXImageWithImageName(@"ifishCamera_start"); return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; //self.cameraModel = [self.yooseeDeviceArr objectAtIndex:indexPath.section]; //先判断是否授权 if (!self.cameraModel.isActive) { [self.view makeToast:@"设备无授权字段"]; return; } //self.cameraModel.isActive = @"1"; if ([self.cameraModel.isActive isEqualToString:@"1"]) { IfishP2PMonitorController *ifishP2p=[[IfishP2PMonitorController alloc] init]; ifishP2p.contact = self.cameraModel ; UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:ifishP2p]; [self presentViewController:nav animated:YES completion:^{ }]; }else if ([self.cameraModel.isActive isEqualToString:@"0"]){ UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"" message:@"请扫描产品外包装上的激活码来激活摄像头" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"前往扫描", nil]; [alert show]; } } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if(buttonIndex == 1){ ScanViewController *scanVC=[[ScanViewController alloc]init]; scanVC.cameraModel = self.cameraModel ; UINavigationController * nVC = [[UINavigationController alloc]initWithRootViewController:scanVC]; [self presentViewController: nVC animated:YES completion:^{ }]; } } @end