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

时间:2016-05-26 08:30:14

标签: ios objective-c

右侧是选择器视图工具栏按钮“下一步”,并希望通过textFieldShouldReturn调用其@selector方法。但它给了我错误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];
}

ScreenShot

1 个答案:

答案 0 :(得分:0)

试试这个......

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

}