Harshil Harshil - 1 year ago 147
iOS Question

How to use textFieldShouldReturn method as selector action?

On the right is picker view toolbar button 'Next' and want to call

textFieldShouldReturn
method on its action via
@selector
. But it gives me error
Undeclared Selector
.
This is button's code,

UIBarButtonItem *nextBtn = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStylePlain target:self action:@selector("textFieldShouldReturn here")];


And this is my textFieldShouldReturn method,

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
self.addScrollView.contentSize = CGSizeMake(320, 1800);
[self.addScrollView setContentOffset:CGPointMake(0, 0 ) animated:NO];

if (textField == industryTxtField) {
[subIndustryTxtField becomeFirstResponder];
}
else if (textField == subIndustryTxtField) {
[address1TxtField becomeFirstResponder];
}


ScreenShot

Answer Source

Try like this ...

UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStylePlain target:self action:@selector(moveToNextField)];

-(void)moveToNextField
{
  if (industryTxtField.isFirstResponder) 
  {
    [subIndustryTxtField becomeFirstResponder];
  }
  else if (subIndustryTxtField.isFirstResponder) 
  {
    [address1TxtField becomeFirstResponder];
  }

}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download