我尝试过以下代码,但出于某种原因,只要按下键盘上的回车键,键盘就不会退出。为什么这不起作用?
$http.post("api.php").success(function(data){
$scope.projects = data; //the data are stored in projects
});
答案 0 :(得分:2)
使用textFieldDelegate,然后使用此代码并将委托自我分配给Viewdidload中的文本字段
class yourClass: UIViewController , UITextFieldDelegate {
func viewDidLoad(){
super.viewDidLoad()
firstTextField.delegate = self
secondTextField.delegate = self
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
firstTextField.resignFirstResponder()
secondTextField.resignFirstResponder()
return true
}
}
答案 1 :(得分:0)
您应该覆盖UITextFieldDelegate
方法textFieldShouldReturn
以返回true
。添加以下代码并将ViewController指定为textfield的委托。
func textFieldShouldReturn(textField: UITextField) -> Bool {
return true
}
答案 2 :(得分:0)
UITextFieldDelegate
UITextField
textFieldShouldReturn
示例强>
firstTextField.delegate = self
firstTextField.returnKeyType = UIReturnKeyType.Done
secondTextField.delegate = self
secondTextField.returnKeyType = UIReturnKeyType.Done
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
答案 3 :(得分:0)
Swift 4 iOS SDK 11.0
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}