UITextField's resignFirstResponder is not working neither working self.view.endEditing()

Try this

func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
   if textField == tfA
   {
       tfaAction()
       return false
   }
   else
   {
       return true
   }
}
func tfaAction(){

 }

Remove your textFieldDidBeginEditing method, replace it with textFieldShouldBeginEditing:

func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
  if textField == tfA{
    print("TFA Clicked")
    self.view.endEditing(true)
    return false
  }else{
    return true
  }
}