Home > DeveloperSection > Forums > Can't Resign keyboard while tap on background?
Jayne Spooner
Jayne Spooner

Total Post:21

Points:147
Posted on    July-21-2015 11:33 PM

 iPhone iPhone  Ios  Objective C 
Ratings:


 1 Reply(s)
 350  View(s)
Rate this:

I am trying to resign keyboard while tap on background but I cann't

 

first I have clicked on editable textfield and open keyboard then I have cliked on another textfield that is not editable after that I have cliked background but I cann't resign keyboard

 

here is my code

-(void)textFieldDidBeginEditing:(UITextField *)textField

 {

if(textField == insertcity)

{

    [self.view endEditing:YES];

    citytable.hidden = NO;

    hoteltable.hidden = YES;

    [self SetDynamicHieghtofTbl:citytable andArr:cityarray];

}

if(textField == inserthotel)

{

[self.view endEditing:YES];

  hoteltable.hidden = NO;

  citytable.hidden = YES;

  [self SetDynamicHieghtofTbl:hoteltable andArr:hotelarray];

 }

 if(self.txt_validationCode.tag == 3)    {       //[self.view endEditing:NO];

    }

}

-(void)textFieldDidEndEditing:(UITextField *)textField

{

   [textField resignFirstResponder];

   if(textField.tag == 3)

   {

    self.enteredCode = textField.text;

   }

}

-(void) backgroundTap: (UITapGestureRecognizer *)recognizer

{

    citytable.hidden = YES;

    hoteltable.hidden = YES;

    [self.txt_validationCode resignFirstResponder];

  }



Tarun Kumar

Total Post:210

Points:1614
Posted on    July-22-2015 11:37 PM

try this or remove the tap gesture and add the following method


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 

[self textFieldResign];

}

-(void)textFieldResign{

[self.txt_validationCode resignFirstResponder];

[self.view endEditing:YES];

// whatever you want use here

}

Don't want to miss updates? Please click the below button!

Follow MindStick