// // IfishKanHuServiceViewController.m // Ifish // // Created by imac on 16/8/19. // Copyright © 2016年 lianxiang. All rights reserved. // #import "IfishKanHuServiceViewController.h" #import "LookafterPicCell.h" #import "LookafterPhoneNumberCell.h" #define TEXT_FIELDPHONENUMB 22223333 #import "MineKanHuViewController.h" #import "CertificationShopModel.h" @interface IfishKanHuServiceViewController () @property(nonatomic,strong)UITableView *tableView; @end @implementation IfishKanHuServiceViewController - (void)viewDidLoad { [super viewDidLoad]; self.title = @"看护服务"; // Do any additional setup after loading the view. [self setUI]; } -(void)goBackAction{ // 审核认证成功也会用此界面 返回 到主界面 [self.navigationController popToRootViewControllerAnimated:YES]; } -(void)setUI{ self.tableView = [[UITableView alloc] init ]; self.tableView.frame =CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height); self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.showsVerticalScrollIndicator = NO; self.tableView.backgroundColor = TABLE_BACKGROUD_COLOR; [self.view addSubview:self.tableView]; } -(void)viewWillAppear:(BOOL)animated{ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(phoneNumberkeyboradWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; } -(void)viewWillDisappear:(BOOL)animated{ [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 2; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.row == 0) { LookafterPicCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LookafterPicCell"]; if (!cell) { cell = [[[NSBundle mainBundle]loadNibNamed:@"LookafterPicCell" owner:self options:nil]lastObject]; } [cell bringSubviewToFront:cell.imgDetaillabel]; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; }else if (indexPath.row == 1){ LookafterPhoneNumberCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LookafterPhoneNumberCell"]; if (!cell) { cell = [[[NSBundle mainBundle]loadNibNamed:@"LookafterPhoneNumberCell" owner:self options:nil]lastObject]; } cell.queRenBtn.layer.masksToBounds= YES; cell.queRenBtn.layer.cornerRadius = 5; UIView*kongbaiView=[[UIView alloc]initWithFrame:CGRectMake(0,0, 10, 10)]; cell.shopPoneNumberFied.leftView=kongbaiView; cell.shopPoneNumberFied.leftViewMode=UITextFieldViewModeAlways; cell.shopPoneNumberFied.layer.masksToBounds = YES; cell.shopPoneNumberFied.layer.cornerRadius = 5; cell.shopPoneNumberFied.userInteractionEnabled = YES; cell.shopPoneNumberFied.delegate = self; cell.tag = TEXT_FIELDPHONENUMB; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.userInteractionEnabled = YES; [cell.queRenBtn addTarget:self action:@selector(querenBtnAction:) forControlEvents:UIControlEventTouchUpInside]; return cell; } return nil; } #pragma mark - 确认按钮事件 -(void)querenBtnAction:(UIButton*)btn{ // self.hidesBottomBarWhenPushed = YES; // // MineKanHuViewController *kanHuVC=[[MineKanHuViewController alloc] init]; // // [self.navigationController pushViewController:kanHuVC animated:YES]; [self selectKanHuShop]; } #pragma mark - 选择看护商家 -(void)selectKanHuShop{ LookafterPhoneNumberCell *cell =[self.view viewWithTag:TEXT_FIELDPHONENUMB]; NSString * MOBILE = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$"; NSPredicate*regextestmobile=[NSPredicate predicateWithFormat:@"SELF MATCHES %@",MOBILE]; BOOL isMacth=[regextestmobile evaluateWithObject:cell.shopPoneNumberFied.text]; if (!isMacth) { [self.view makeToast:@"请输入正确手机号"]; return; } __weak typeof(self) weakself= self; UserModel* usermodel=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"]; [IFISHHTTPTOOL xuanZeKanHuShnagJiaWith: cell.shopPoneNumberFied.text UserId: usermodel.userId xuaZeShangJia:^(CertificationShopModel *kanHuShangJia) { [weakself showWoDeKanHuWith:kanHuShangJia]; }]; } -(void)showWoDeKanHuWith:(CertificationShopModel *)model{ if (model) { MineKanHuViewController *wodeKanHu=[[MineKanHuViewController alloc] init]; wodeKanHu.xinXiModel = model; self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:wodeKanHu animated:YES]; } } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ CGFloat imgH= kScreenSize.width * 0.56; if (indexPath.row ==0) { return imgH + 8 + 20; }else if (indexPath.row ==1){ return 210; } return 0; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [self hiddenKeybord]; } #pragma mark-处理收键盘 -(BOOL)textFieldShouldReturn:(UITextField *)textField{ [textField resignFirstResponder]; return YES; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self hiddenKeybord]; } -(void)hiddenKeybord{ LookafterPhoneNumberCell *cell =[self.view viewWithTag:TEXT_FIELDPHONENUMB]; [cell.shopPoneNumberFied resignFirstResponder]; } -(void)phoneNumberkeyboradWillShow:(NSNotification *)notification{ LookafterPhoneNumberCell *cell=[self.tableView viewWithTag:TEXT_FIELDPHONENUMB]; CGFloat kbHeight = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height; // CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; //计算出键盘顶端到inputTextView panel底端的距离(加上自定义的缓冲距离INTERVAL_KEYBOARD) CGRect hopPoneNumRect = [cell.shopPoneNumberFied convertRect:cell.shopPoneNumberFied.bounds toView:self.view]; CGFloat offset = (hopPoneNumRect.origin.y+hopPoneNumRect.size.height+INTERVAL_KEYBOARD) - (self.tableView.frame.size.height - kbHeight); // 取得键盘的动画时间,这样可以在视图上移的时候更连贯 double duration = [[notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; if(offset > 0) { [UIView animateWithDuration:duration animations:^{ self.view.frame = CGRectMake(0.0f, -offset , self.view.frame.size.width, self.view.frame.size.height); }]; } } //恢复原始视图位置 /////键盘消失事件 - (void) keyboardWillHide:(NSNotification *)notify { // 键盘动画时间 double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; //视图下沉恢复原状 [UIView animateWithDuration:duration animations:^{ self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); }]; } @end