如何为第一个textField启用返回键到下一个textField,并为最后一个文本字段执行与Login按钮相同的功能?
答案 0 :(得分:0)
这是示例代码
- (BOOL) textFieldShouldReturn:(UITextField *) textField {
if (textField == textField1) {
[textField2 becomeFirstResponder];
} else if (textField == textField2) {
[textField3 becomeFirstResponder];
} else if (textField == textField3) {
[textField resignFirstResponder];
[self callAPI]; //Call API Assuming it the last field
}
return YES;
}
Swift版
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if textField == textField1 {
textField2.becomeFirstResponder()
} else if textField == textField2 {
textField3.becomeFirstResponder()
} else if textField == textField3 {
textField.resignFirstResponder()
self.callAPI()
}
return true
}
答案 1 :(得分:0)
使用self.view.endEditing = true