我已經搜索並看到了很多關於textFieldShouldReturn方法的答案。其中一半已經過時,一些在不同情況下工作,有些則沒有詳細解釋。我不確定什麼是最好的方式來完成這項任務,它的工作原理,但我認爲可能有一個更簡單的方法來做到這一點。Text Field Should Return,this is correct for ios7?
繼承人到目前爲止我的代碼:
在頭文件:
@interface ClassName : SomeUIViewController <UITextFieldDelegate>
在實現文件:
@interface ClassName()
@property (weak, nonatomic) IBOutlet UITextField *firstOne;
@property (weak, nonatomic) IBOutlet UITextField *secondOne;
@property (weak, nonatomic) IBOutlet UITextField *thirdOne;
@property (weak, nonatomic) IBOutlet UITextField *fourthOne;
@property (weak, nonatomic) IBOutlet UITextField *fifthOne;
@end
-(void)viewDidLoad{
self.firstOne.delegate = self;
self.secondOne.delegate = self;
self.thirdOne.delegate = self;
self.fourthOne.delegate = self;
self.fifthOne.delegate = self;
}
-(BOOL)textFieldShouldReturn:(UITextField*)textField;
{
if (textField == self.firstOne) {
[textField resignFirstResponder];
[self.secondOne becomeFirstResponder];
} else if (textField == self.secondOne) {
[textField resignFirstResponder];
[self.thirdOne becomeFirstResponder];
} else if (textField == self.thirdOne) {
[textField resignFirstResponder];
[self.fourthOne becomeFirstResponder];
} else if (textField == self.fourthOne) {
[textField resignFirstResponder];
[self.fifthOne becomeFirstResponder];
} else if (textField == self.fifthOne) {
[textField resignFirstResponder];
}
return NO;
}
所以這是正確的還是有更好的方法來做到這一點任務?
如果您使用IB(Interface Builder),您可以在代碼中設置委託,而不是在代碼中。 – zaph
看起來不錯。我做了類似的事情,它的工作。 – dasdom