2

I have two text fields in my view. I did it using IB. in second text field i am using the action sheet

After entering the text in textField1 I am in text Field-2.In second text field i am using the action sheet with a picker to select the date. so i resigned the textfield -2 keyboard before opening the action sheet. after i dismiss the action sheet when i tried to resign the keyboard it is not returning. i used

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textfield1 resignFirstResponder];
    return YES;
}  

to resign the textfield1 ..

4 Answers 4

4
- (void) viewDidLoad
{
   //don't forget to add <UITextFieldDelegate> in your .h
   firstTextField.delegate=self;
   secondTextField.delegate=self;
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if(textField.tag==2)
    {
      //Here you can call function to view your datepicker
      return NO; //Will not open keyboard for second textfield.
    }
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}
0
0

You have return current textField textFieldShouldReturn method change your textFieldShouldReturn metod like below

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
0

You need to Give the tag for TextField,

Within this method,

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{              
    if (textField.tag == 2)
    {
       [textField1 resignFirstResponder];
       // your action sheet code here 
    } 
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField           
{
   [textfield resignFirstResponder]
   return YES;
}  
1
  • with out returning the 1st text field keyboard i am passing to 2nd one . the text field for the 2nd field is not opening as i resigned it as first responder ..but keyboard of the 1st field is not resigning@
    – vamsi575kg
    Mar 20, 2012 at 11:25
0

Set tag to every text fields and check them in

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if([textfield.tag == 1])
   {
       [textFieldFirst resignFirstResponder];
   }
   else
   {
     // your action sheet code here
   }
   return YES;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.