如何使用textFieldShouldReturn方法作为选择器操作



右侧是选择器视图工具栏按钮"下一步",并希望通过@selector调用textFieldShouldReturn方法的操作。但它给了我错误Undeclared Selector.这是按钮的代码,

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

这是我的textFieldShouldReturn方法,

-(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];
}

屏幕截图

试试这样...

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];
  }
}

最新更新