| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640 |
- //
- // ViewController.m
- // Haishenghai-master
- //
- // Created by GG on 2018/12/29.
- // Copyright © 2018年 Haishenghai intelligence network technology. All rights reserved.
- //
- #import "ViewController.h"
- #import "PlaceModel.h"
- #import <SRWebSocket.h>
- #import <JPUSHService.h>
- #import <AVFoundation/AVFoundation.h>//音视频框架
- #import "CheckMessage_VC.h"
- @interface ViewController ()<UITableViewDelegate,UITableViewDataSource,UIPopoverControllerDelegate,UIPopoverPresentationControllerDelegate>
- {
- // SRWebSocket *_webSocket;
- UILabel *remindText;
- int _deviceStatus;
- int _fireAlarm;
- NSString *fireAlarmContent;
- }
- //- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message;
- @end
- static NSInteger seq = 0;
- @implementation ViewController
- ////webSocket数据包
- //- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message{
- // NSLog(@"%@",message);
- // if ([message isEqualToString:@"login"]) {
- // NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- // [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
- // NSDate *datenow = [NSDate date];
- // NSString *currentTimeString = [formatter stringFromDate:datenow];
- // UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:[NSString stringWithFormat:@"你的海盛海智联账号于%@在异地设备上通过密码登录。若果不是你操作,你的账号密码已经泄露。请尽快修改密码",currentTimeString] preferredStyle:UIAlertControllerStyleAlert];
- // [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- //
- // [_webSocket close];
- // //退出
- // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[UserLogin_VC alloc] init]];
- // [UIApplication sharedApplication].keyWindow.rootViewController = nav;
- //
- // }]];
- // [self presentViewController:alert animated:YES completion:nil];
- //
- //
- // }else{
- //// if ([message isKindOfClass:[NSString class]]) {
- //// 将json字符串转换成字典
- // NSError *error;
- // NSData * getJsonData = [message dataUsingEncoding:NSUTF8StringEncoding];
- // NSDictionary * getDict = [NSJSONSerialization JSONObjectWithData:getJsonData options:NSJSONReadingMutableContainers error:&error];
- // NSDictionary *service = [getDict objectForKey:@"service"];
- // NSDictionary *dataDic = [service objectForKey:@"data"];
- // NSString *deveStatus = [dataDic objectForKey:@"deviceStatus"];
- // NSString *fire = [dataDic objectForKey:@"fireAlarm"];
- // _deviceStatus = [deveStatus intValue];
- // _fireAlarm = [fire intValue];
- // NSLog(@"这是webSocket发的数据%d--%d",_deviceStatus,_fireAlarm);
- //
- //// }
- // //改变状态
- // if (_fireAlarm==1 &&_deviceStatus==8) {
- // _topImageView.image = [UIImage imageNamed:@"hsh_home_alert_top"];
- //
- // }else if (_fireAlarm !=1&& _deviceStatus !=8){
- // _topImageView.image = [UIImage imageNamed:@"hsh_home_normal_top"];
- //
- // }else if (_fireAlarm ==1&&_deviceStatus !=8){
- // _topImageView.image = [UIImage imageNamed:@"hsh_home_alert_top"];
- //
- // }else if (_fireAlarm !=1&&_deviceStatus ==8){
- // _topImageView.image = [UIImage imageNamed:@"hsh_home_fault_top"];
- //
- // }
- // [self.tableView reloadData];
- // //重新请求数据刷新
- // }
- //
- //}
- //
- #pragma mark - Life Circle
- - (void)viewDidLoad {
- [super viewDidLoad];
- [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(fireChage:) name:@"fireChange" object:nil];
- [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(fireChage:) name:@"appQuitChange" object:nil];
- // Do any additional setup after loading the view, typically from a nib.
- //先跑viewcontrller
- //生成当前时间时间戳
- // NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
- // [formatter setDateStyle:NSDateFormatterMediumStyle];
- // [formatter setTimeStyle:NSDateFormatterShortStyle];
- // [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss SSS"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
- // //设置时区,这个对于时间的处理有时很重要
- // NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
- // [formatter setTimeZone:timeZone];
- // NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
- // NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]*1000];
- // NSString *userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userid"];
- // NSString *urlString = [NSString stringWithFormat:@"ws://www.hsh-iot.cn/YunGanKeJi/websocket/%@:%@",userId,timeSp];
- // _webSocket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:urlString]];
- // _webSocket.delegate = self;
- //
- // [_webSocket open];
- [self setupUI];
- //集成下拉刷新控件
- [self setupDownRefresh];
-
- //集成上拉刷新控件
- // [self setupUpRefresh];
- //-------------------------------------------------------------------
- NSString *LoginID = [[NSUserDefaults standardUserDefaults]objectForKey:@"loginId"];
- [JPUSHService setAlias:LoginID completion:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
- [self inputResponseCode:iResCode content:iAlias andSeq:seq];
- } seq:[self seq]];
- // 注册极光通知观察者
- //注册通知观察者
- NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
- [defaultCenter addObserver:self
- selector:@selector(networkDidSetup:)
- name:kJPFNetworkDidSetupNotification
- object:nil];
- [defaultCenter addObserver:self
- selector:@selector(networkDidClose:)
- name:kJPFNetworkDidCloseNotification
- object:nil];
- [defaultCenter addObserver:self
- selector:@selector(networkDidRegister:)
- name:kJPFNetworkDidRegisterNotification
- object:nil];
- [defaultCenter addObserver:self
- selector:@selector(networkDidLogin:)
- name:kJPFNetworkDidLoginNotification
- object:nil];
- [defaultCenter addObserver:self
- selector:@selector(networkDidReceiveMessage:)
- name:kJPFNetworkDidReceiveMessageNotification
- object:nil];
-
- //添加alias
-
-
-
- //查询当前设置的alias
- // [JPUSHService getAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
- // [self inputResponseCode:iResCode content:iAlias andSeq:seq];
- // } seq:[self seq]];
-
-
- }
- - (void)inputResponseCode:(NSInteger)code content:(NSString *)content andSeq:(NSInteger)seq{
- NSLog (@"\n\n code:%ld content:%@ seq:%ld", code, content, seq);
- }
- - (NSInteger)seq {
- return ++ seq;
- }
- //与极光服务端建立长连接
- - (void)networkDidSetup:(NSNotification *)notification {
- }
- //长连接关闭
- - (void)networkDidClose:(NSNotification *)notification {
- }
- //注册成功
- - (void)networkDidRegister:(NSNotification *)notification {
- }
- //登录成功
- - (void)networkDidLogin:(NSNotification *)notification {
-
- }
- //自定义消息通知消息
- -(void)networkDidReceiveMessage:(NSNotification *)notification{
-
- NSDictionary *userInfo = [notification userInfo];
- NSLog(@"这是收到自定义消息通知%@",userInfo);
- NSError *error;
- NSString *content = [userInfo objectForKey:@"content"];
- //这是收到的推送的消息
- NSData *getJsonData = [content dataUsingEncoding:NSUTF8StringEncoding];
- NSDictionary * getDict = [NSJSONSerialization JSONObjectWithData:getJsonData options:NSJSONReadingMutableContainers error:&error];
- // NSLog(@"----------这是content%@",getDict);
- // NSUInteger messageID = [[userInfo objectForKey:@"_j_msgid"] unsignedIntegerValue];
- NSString *data = [getDict objectForKey:@"data"];
- NSData *dataString = [data dataUsingEncoding:NSUTF8StringEncoding];
- NSDictionary * dataDict = [NSJSONSerialization JSONObjectWithData:dataString options:NSJSONReadingMutableContainers error:&error];
- // NSLog(@"----------这是data%@",dataDict);
- NSString *fireAlarm = [dataDict objectForKey:@"fireAlarm"];
- NSString *deviceStatus = [dataDict objectForKey:@"deviceStatus"];
-
- NSString *eventTime = [dataDict objectForKey:@"eventTime"];
- NSString *deviceId = [dataDict objectForKey:@"deviceId"];
- NSString *deviceName = [dataDict objectForKey:@"deviceName"];
- NSString *siteName = [dataDict objectForKey:@"siteName"];
- NSString *siteLocation = [dataDict objectForKey:@"siteLocation"];
- NSString *regionName = [dataDict objectForKey:@"regionName"];
- if ([fireAlarm isEqualToString:@"1"]&&[deviceStatus isEqualToString:@"0"]) {
- [self.tableView.mj_header beginRefreshing];
- //播放报警声音
- [self playSound];
- NSString *alertContent = [NSString stringWithFormat:@"发生时间:%@\n设备编号:%@\n设备名称:%@\n场所名称:%@\n安装位置:%@\n详细地址:%@\n" ,eventTime,deviceId,deviceName,siteName,regionName,siteLocation];
- NSLog(@"这是极光推送的消息%@",alertContent);
-
- fireAlarmContent = alertContent;
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"尊敬的用户,您的设备发生火警请及时处理" message:alertContent preferredStyle:UIAlertControllerStyleAlert];
- [alert addAction:[UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- if(self.player.playing) {
- [self.player stop];
- self.player =nil;
- [[NSNotificationCenter defaultCenter]removeObserver:self];
- [alert removeFromParentViewController];
- }
- //
- CheckMessage_VC *message = [[CheckMessage_VC alloc]init];
- message.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:message animated:YES];
-
- }]];
- [self presentViewController:alert animated:YES completion:nil];
- }else{
- //故障
- }
- }
- #pragma mark-----收到火警消息之后的操作
- -(void)playSound{
- // 播放系统声音
- //定义一个SystemSoundID
- // SystemSoundID soundID = 1331;
- //// 播放声音
- // AudioServicesPlaySystemSound(soundID);
-
- NSString *filePath = [[NSBundle mainBundle] pathForResource:@"fireAlarm" ofType:@"mp3"];
- NSURL *fileUrl = [NSURL URLWithString:filePath];
- self.player = [[AVAudioPlayer alloc]initWithContentsOfURL:fileUrl error:nil];
- //设置声音的大小
- self.player.volume =1;
- //设置循环次数 ,如果为负数,就是无限循环
- self.player.numberOfLoops = -1;
- //准备播放
- [self.player prepareToPlay];
- //播放
- [self.player play];
- }
- -(void)fireChage:(NSNotification *)noti{
- NSLog(@"6666666666");
- // NSDictionary *userInfo = [noti userInfo];
- // NSLog(@"这是收到自定义消息通知%@",userInfo);
- // NSError *error;
- // NSString *content = [userInfo objectForKey:@"content"];
- //
- // //这是收到的推送的消息
- // NSData *getJsonData = [content dataUsingEncoding:NSUTF8StringEncoding];
- // NSDictionary * getDict = [NSJSONSerialization JSONObjectWithData:getJsonData options:NSJSONReadingMutableContainers error:&error];
- // // NSLog(@"----------这是content%@",getDict);
- // // NSUInteger messageID = [[userInfo objectForKey:@"_j_msgid"] unsignedIntegerValue];
- // NSString *data = [getDict objectForKey:@"data"];
- // NSData *dataString = [data dataUsingEncoding:NSUTF8StringEncoding];
- // NSDictionary * dataDict = [NSJSONSerialization JSONObjectWithData:dataString options:NSJSONReadingMutableContainers error:&error];
- // // NSLog(@"----------这是data%@",dataDict);
- // NSString *fireAlarm = [dataDict objectForKey:@"fireAlarm"];
- // NSString *deviceStatus = [dataDict objectForKey:@"deviceStatus"];
- //
- // NSString *eventTime = [dataDict objectForKey:@"eventTime"];
- // NSString *deviceId = [dataDict objectForKey:@"deviceId"];
- // NSString *deviceName = [dataDict objectForKey:@"deviceName"];
- // NSString *siteName = [dataDict objectForKey:@"siteName"];
- // NSString *siteLocation = [dataDict objectForKey:@"siteLocation"];
- // NSString *regionName = [dataDict objectForKey:@"regionName"];
- // if ([fireAlarm isEqualToString:@"1"]&&[deviceStatus isEqualToString:@"0"]) {
- // //播放报警声音
- [self playSound];
- // NSString *alertContent = [NSString stringWithFormat:@"发生时间:%@\n设备编号:%@\n设备名称:%@\n场所名称:%@\n安装位置:%@\n详细地址:%@\n" ,eventTime,deviceId,deviceName,siteName,regionName,siteLocation];
- // NSLog(@"这是极光推送的消息%@",alertContent);
- //
- // fireAlarmContent = alertContent;
- [self.tableView.mj_header beginRefreshing];
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"尊敬的用户,您的设备发生火警请及时处理" message:@"" preferredStyle:UIAlertControllerStyleAlert];
- [alert addAction:[UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- if(self.player.playing) {
- [self.player stop];
- self.player =nil;
- [[NSNotificationCenter defaultCenter]removeObserver:self];
- [alert removeFromParentViewController];
-
-
- }
- //
- CheckMessage_VC *message = [[CheckMessage_VC alloc]init];
- message.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:message animated:YES];
-
- }]];
- [self presentViewController:alert animated:YES completion:nil];
- }
- -(void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self.navigationController setNavigationBarHidden:NO animated:NO];
- [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
-
- [self.navigationController.navigationBar setShadowImage:[UIImage new]];
- // [DataSourceManager getSiteWithUrlPagesize:@"10" Page:@"1" completionBlock:^(NSMutableArray *array) {
- //
- // _dataArray = array;
- // [_tableView reloadData];
- // }];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tableDidSelected:) name:@"click" object:nil];
-
- }
- // 如果不想让其他页面的导航栏变为透明 需要重置
- //在页面消失的时候就让navigationbar还原样式
- -(void)viewWillDisappear:(BOOL)animated{
-
- [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
- [self.navigationController.navigationBar setShadowImage:nil];
- }
- -(void)viewDidDisappear:(BOOL)animated{
- [[NSNotificationCenter defaultCenter]removeObserver:self name:@"click" object:nil];
- self.navigationController.navigationBarHidden =NO;
- }
- //#pragma mark - SRWebSocketDelegate
- /////--------------------------------------
- //
- //- (void)webSocketDidOpen:(SRWebSocket *)webSocket;
- //{
- // NSLog(@"Websocket Connected");
- //}
- //
- //- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error;
- //{
- // NSLog(@":( Websocket Failed With Error %@", error);
- //
- //// _webSocket = nil;
- //}
- //
- //- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessageWithString:(nonnull NSString *)string
- //{
- // NSLog(@"Received \"%@\"", string);
- // // [self _addMessage:[[TCMessage alloc] initWithMessage:string incoming:YES]];
- //}
- //
- //- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;
- //{
- // NSLog(@"WebSocket closed");
- // _webSocket = nil;
- //}
- //
- //- (void)webSocket:(SRWebSocket *)webSocket didReceivePong:(NSData *)pongPayload;
- //{
- // NSLog(@"WebSocket received pong");
- //}
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- -(void)setupUI{
- self.view.backgroundColor = [UIColor whiteColor];
- /** 设置导航栏 */
- self.navigationItem.title =@"海盛海智联";
- [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20],NSForegroundColorAttributeName:[UIColor whiteColor]}];
- UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
- leftButton.frame = CGRectMake(0, 0, 22, 22);
- [leftButton setBackgroundImage:[UIImage imageNamed:@"hsh_home_guide"] forState:UIControlStateNormal];
- [leftButton addTarget:self action:@selector(studyBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- // UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:leftButton];
-
- UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
- rightButton.frame = CGRectMake(0, 0, 44, 44);
- [rightButton setImage:[UIImage imageNamed:@"hsh_home_add_white"] forState:UIControlStateNormal];
- [rightButton addTarget:self action:@selector(addBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightButton];
- // self.navigationItem.leftBarButtonItem =leftItem;
- self.navigationItem.rightBarButtonItem = rightItem;
-
- _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-64) style:UITableViewStylePlain];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.userInteractionEnabled = YES;
- _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
- [self.view addSubview:_tableView];
- //设置表头
- _topImageView = [[UIImageView alloc]init];
- _topImageView.frame = CGRectMake(0, 0, self.view.frame.size.width, 278);
- // _topImageView.contentMode = UIViewContentModeScaleToFill;
- _tableView.tableHeaderView = _topImageView;
- _topImageView.image = [UIImage imageNamed:@"hsh_home_normal_top"];
- self.tableView.showsVerticalScrollIndicator = NO;
-
- remindText = [[UILabel alloc]init];
- remindText.frame = CGRectMake(self.view.frame.size.width/2-60, self.view.frame.size.height*0.6, 120, 44);
- [self.tableView addSubview:remindText];
- remindText.textAlignment = NSTextAlignmentCenter;
- remindText.text = @"场所很安全";
- //加载GIF图 这里的contentmode 需要设置成UIViewContentModeScaleAspectFit;图片则不是
- /* FLAnimatedImageView *bannerImageView = [FLAnimatedImageView new];
- bannerImageView.contentMode = UIViewContentModeScaleAspectFill;
- bannerImageView.frame = CGRectMake(0, 0, self.view.frame.size.width, 250);
- NSString *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]]pathForResource:@"hsh_home_normal_gif" ofType:@"gif"];
- NSData *imageData = [NSData dataWithContentsOfFile:filePath];
- bannerImageView.backgroundColor = [UIColor clearColor];
- bannerImageView.animatedImage = [FLAnimatedImage animatedImageWithGIFData:imageData];
- */
- // [_tableView.tableHeaderView addSubview: _topImageView];
-
- if (@available (iOS 11.0,*)) {
- self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }else{
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
-
- }
- #pragma mark---上拉下拉刷新---
- /**
- * 集成上拉刷新控件
- */
- - (void)setupUpRefresh
- {
- self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreDatas)];
- [self.tableView.mj_footer beginRefreshing];
- }
- /**
- * 集成下拉刷新控件
- */
- - (void)setupDownRefresh
- {
-
- // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadNewData方法)
- self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewDatas)];
- //马上进入刷新状态
- [self.tableView.mj_header beginRefreshing];
- }
- -(void)loadNewDatas{
- _pageIndex =1;//默认加载第一页
- [self.dataArray removeAllObjects];
- //请求数据
- //请求数据
- [DataSourceManager getTroubleSiteWithUrlPagesize:100 Page:_pageIndex completionBlock:^(NSMutableArray *array) {
- _dataArray = array;
- if (_dataArray.count ==0) {
- remindText.hidden = NO;
- }else{
- remindText.hidden = YES;
- }
- [_tableView reloadData];
- //拿到当前的下拉刷新控件,结束刷新
- [self.tableView.mj_header endRefreshing];
- }];
- }
- -(void)loadMoreDatas{
- //1.设置页数
- _pageIndex++;//默认加载第一页
- //请求数据
- [DataSourceManager getSiteWithUrlPagesize:100 Page:1 completionBlock:^(NSMutableArray *array) {
- [_dataArray addObjectsFromArray:array];
- [_tableView reloadData];
- //拿到当前的下拉刷新控件,结束刷新
- self.tableView.estimatedRowHeight = 0;
- self.tableView.estimatedSectionHeaderHeight = 0;
- self.tableView.estimatedSectionFooterHeight = 0;
- [self.tableView.mj_footer endRefreshing];
- }];
- [self.tableView.mj_footer endRefreshing];
- }
- #pragma mark-- tableviewDelegate
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.dataArray.count;
- }
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 60;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- static NSString *cellId = @"cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
- if (!cell) {
- cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId];
- }
- //让单元格的分割线和Cell一样宽
- cell.preservesSuperviewLayoutMargins = false;
- cell.separatorInset = UIEdgeInsetsZero;
- cell.layoutMargins = UIEdgeInsetsZero;
- troubleSiteModel *place = [_dataArray objectAtIndex:indexPath.row];
- if ([place.troubleType isEqualToString:@"1"]) {
- cell.imageView.image = [UIImage imageNamed:@"hsh_home_alert"];
- _topImageView.image = [UIImage imageNamed:@"hsh_home_alert_top"];
- }else if ([place.troubleType isEqualToString:@"0"]){
- cell.imageView.image = [UIImage imageNamed:@"hsh_home_fault"];
- _topImageView.image = [UIImage imageNamed:@"hsh_home_fault_top"];
- }else{
- _topImageView.image = [UIImage imageNamed:@"hsh_home_normal_top"];
- }
- cell.textLabel.text = place.deployment;
- cell.detailTextLabel.text =place.location;
- return cell;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return 60;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
- return 0;
- }
- -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
- UIView *headerView = [[UIView alloc]init];
- headerView.backgroundColor = [UIColor whiteColor];
- UILabel *titlelab = [[UILabel alloc]init];
- titlelab.frame = CGRectMake(0, 0, self.view.frame.size.width, 60);
- titlelab.text = @"区域场所";
- titlelab.font = [UIFont systemFontOfSize:24];
- titlelab.textAlignment = NSTextAlignmentCenter;
- [headerView addSubview:titlelab];
-
- UIView *line = [[UIView alloc]init];
- line.frame = CGRectMake(0, 59, self.view.frame.size.width, 1);
- line.backgroundColor = [UIColor colorWithRed:227/255.0 green:227/255.0 blue:227/255.0 alpha:1];
- [headerView addSubview:line];
- return headerView;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- [tableView deselectRowAtIndexPath:indexPath animated:YES];//反选
- troubleSiteModel *place = [_dataArray objectAtIndex:indexPath.row];
- DetailDeveceList_VC *detailVC = [[DetailDeveceList_VC alloc ]init];
- detailVC.siteID = place.siteId;
- detailVC.hidesBottomBarWhenPushed =YES;
- [self.navigationController pushViewController:detailVC animated:YES];
- }
- #pragma mark---respose Event
- -(void)addBtnClick:(UIButton *)addBtn{
-
- self.itemPopVC = [[popViewController alloc] init];
- self.itemPopVC.modalPresentationStyle = UIModalPresentationPopover;
- self.itemPopVC.popoverPresentationController.barButtonItem = self.navigationItem.rightBarButtonItem; //rect参数是以view的左上角为坐标原点(0,0)
- self.itemPopVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUnknown; //箭头方向,如果是baritem不设置方向,会默认up,up的效果也是最理想的
- self.itemPopVC.popoverPresentationController.delegate = self;
- [self presentViewController:self.itemPopVC animated:YES completion:nil];
- }
- //处理popover上的talbe的cell点击
- - (void)tableDidSelected:(NSNotification *)notification {
- NSIndexPath *indexpath = (NSIndexPath *)notification.object;
- switch (indexpath.row) {
- case 0:
- {
- AddDevece_VC *deveceVC = [[AddDevece_VC alloc]init];
- deveceVC.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:deveceVC animated:YES];
- }
- break;
- case 1:
- {
- Addplace_VC *placeVC = [[Addplace_VC alloc]init];
- placeVC.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:placeVC animated:YES];
- }
- break;
- }
- if (self.buttonPopVC) { //我暂时使用这个方法让popover消失,但我觉得应该有更好的方法,因为这个方法并不会调用popover消失的时候会执行的回调。
- [self.buttonPopVC dismissViewControllerAnimated:YES completion:nil];
- self.buttonPopVC = nil;
- }else{
- [self.itemPopVC dismissViewControllerAnimated:YES completion:nil];
- self.itemPopVC = nil;
- }
- }
- - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{
- return UIModalPresentationNone;
- }
- - (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController{
- return YES;
- //no点击蒙版popover不消失, 默认yes
- }
- -(void)studyBtnClick:(UIButton *)studyBtn{
-
- }
- - (void)dealloc {
-
- // [self unObserveAllNotifications];
- }
- - (void)unObserveAllNotifications {
- NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
- [defaultCenter removeObserver:self
- name:kJPFNetworkDidSetupNotification
- object:nil];
- [defaultCenter removeObserver:self
- name:kJPFNetworkDidCloseNotification
- object:nil];
- [defaultCenter removeObserver:self
- name:kJPFNetworkDidRegisterNotification
- object:nil];
- [defaultCenter removeObserver:self
- name:kJPFNetworkDidLoginNotification
- object:nil];
- [defaultCenter removeObserver:self
- name:kJPFNetworkDidReceiveMessageNotification
- object:nil];
- [defaultCenter removeObserver:self
- name:kJPFServiceErrorNotification
- object:nil];
- }
- @end
|