Question

I am designed one form with four UITextFields. First One for entering numbers, Second for entering name, third for choosing date and last one for choosing time. First textfield using Numberpad it will hide by using done button on the keyboard. If the user when enter into second (Name textfield) from first (number textfield) the first keyboard hide perfectly. If the user entering name and select date textfield am showing the datepicker in Actionsheet, when the user pick the date and hit done/cancel button i hide the actionsheet. But, the name textfield keyboard don't dismiss from the screen. I have tied below code, it is not working. Can anyone please suggest the idea for this clarification? Thanks in advance.

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    if (textField == numberTextfield) 
    {
        [textField setInputAccessoryView:keyboardToolbar]; 

    }
    else if(textField == nameTextfield)
    {

    }
    else if(textField == dateTextField)
    {
        [self showdateActionSheet];

        [nameTextfield resignFirstResponder];
        [dateTextField resignFirstResponder];
    }
    else if(textField == timeTextField)
    {         
        [timeTextField resignFirstResponder];
        [nameTextfield resignFirstResponder];
    }
} 

- (BOOL) textFieldShouldReturn:(UITextField *)textField  // If the user select Return key it is dismissing fine
{ 
    [nameTextfield resignFirstResponder];

    return YES;
}

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

-(void) DateDone
{
   [nameTextfield resignFirstResponder];
}

-(void) timeDone
{
   [nameTextfield resignFirstResponder];
}
Was it helpful?

Solution

Gopinath. Please try my following code,

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{ 
    if (textField == dateTextField )
    {  
        [nameTextfield resignFirstResponder]; 

        [self showdateActionSheet];

        [dateTextField resignFirstResponder];
    }
    else if( textField == timeTextField)
    {
        [nameTextfield resignFirstResponder];
        [self ShowTime];
        [timeTextField resignFirstResponder];
    }
    return YES; 
}

I am sure i will help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top