I am facing a ridiculous problem for textField, I have two text fields, namely tfA and tfB, I set delegates and everything for these text fields, what I wanted, if I click on tfA, then it should print something, and itβs printing and if I press tfB, the keyboard should appear, well, it works well too, but when I press tfA again, it should print something, and the keyboard should deviate in accordance with the given condition, but the keyboard there doesnβt turn off either self.view.endEditing(true)does not work here. The code is below with a screenshot, what am I doing wrong here?
CODE: Swift 3
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var tfA: UITextField!
@IBOutlet weak var tfB: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
tfA.delegate = self
tfB.delegate = self
}
func textFieldDidBeginEditing(_ textField: UITextField) {
if textField == tfA{
print("TFA Clicked")
textField.resignFirstResponder()
self.view.endEditing(true)
}else{
tfB.becomeFirstResponder()
}
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Screenshots
