How to give a button iPhone onScreenKeyboard return key behaviour?

I have an application where I have to implement customised QuickType Suggestion at the top of onScreen Keyboard. Where(QuickType Suggestion Box) the right button behaviour is like as that keyboard return type behaviour. If the keyBoard return key is "next" then the suggestion's right key will be "next", if "Done" then it also has to be "Done" along with the type action. I had attested three buttons along with the top of that keyboard when it's appear. But I can't figure out, how to work with it? Is it possible to do with this trick? and how? If, there another ways to do that, please suggest.

enter image description here

Upvotes: 0

Views: 591

Answers (3)

The following way worked for me:

-(IBAction)customNextButtonAction:(id)sender {

 for (UITextField *textField in [self.textFieldContainingView subviews]) {
     if ([textField isKindOfClass:[UITextField class]] && textField == self.desiredTextField) {
        [self.desiredTextField resignFirstResponder];
        UIView *next = self.nextTextField;
        [next becomeFirstResponder];
    }
}

}

Thanks all to help me.

Upvotes: 0

Anurag Bhakuni
Anurag Bhakuni

Reputation: 2439

1.first, you need to find what is your textfield returnkeytype and then make a Barberton on toolbar according to it.

-(void)customizeToolbarMethod
  {
     if(textField.returnKeyType == UIReturnKeyNext)
       {
        UIBarButtonItem *barBtnPrev = [[UIBarButtonItem alloc] initWithTitle:@"Next"
                                                                           style:UIBarButtonItemStyleBordered
                                                                          target:self action:@selector(actionBtnNextForPassword)];
       }
    else if(textField.returnKeyType == UIReturnKeyDone)
       {
    UIBarButtonItem *barBtnDone = [[UIBarButtonItem alloc] initWithTitle:@"Done"
                                                                       style:UIBarButtonItemStyleDone
                                                                      target:self action:@selector(actionResignKeyBoard)];
       }  
 //set this bar button onto your toolbar by making them array of bar-button
  } 
-(void) actionBtnNextForPassword
 {
           //do what you want to do......
 }
-(void)actionResignKeyBoard
 {
           //do what you want to do......
 }

Upvotes: 1

Okey so first you need to know what is the type of your keyboard button and if the button is next then your text fields should have a unique tag foreach one :

-(IBAction)didTapOnCustomNextButton:(id)sender
{
    UITextField * textField = (UITextField *)sender ;

    if(textField.returnKeyType == UIReturnKeyNext)
    {
       NSInteger nextTextField = textField.tag+1;

       UIResponder* responder = [textField.superview viewWithTag:nextTextField];

       if (responder!=nil) 
       {
          [responder becomeFirstResponder];
       } 
       else 
       {
         [textField resignFirstResponder];
       }
    }
    else
    {
       [textField resignFirstResponder];
    }

}

Edit 1: i edited my code to work in an IBAction and also fixed some variables names

Upvotes: 1

Related Questions