2016-05-26 54 views
-5

右側是選取器視圖工具欄按鈕'下一步',並且想通過@selector在其動作中調用textFieldShouldReturn方法。但它給我錯誤Undeclared Selector。 這是按鈕的代碼,如何使用textFieldShouldReturn方法作爲選擇器動作?

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

+0

你有什麼錯誤,按鈕聲明還是函數?你在哪裏調用函數? – gbalduzzi

+0

一旦檢查您打開和關閉了多少個大括號,並且該方法需要返回值(Bool值),那麼您返回了什麼? – raki

+0

按鈕聲明給我警告「Undeclared selector textfieldShouldReturn」 – Harshil

回答

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

} 
+0

這工作:)大謝謝! – Harshil

相關問題