如何在xcode中启用ios键盘返回键功能?

时间:2017-06-19 12:54:30

标签: ios swift3 keyboard xcode8

如何为第一个textField启用返回键到下一个textField,并为最后一个文本字段执行与Login按钮相同的功能?

2 个答案:

答案 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