1

I am trying to get UITextField that on which the observer UIKeyboardDidShowNotification is being called.

My Observer is in appdelegate and I have several UIViewControllers that have several UITextFields in them, in short I don't know current First Responder.

How can I get the first responder inside my Method that is fired upon the keyboard notification UIKeyboardDidShowNotification?

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Hassy
  • 5,068
  • 5
  • 38
  • 63
  • If you only need to know what text field just got the focus, consider handling the `UITextFieldTextDidBeginEditingNotification`. It passes the text field in the `object` parameter. – Daniil Korotin Oct 06 '15 at 12:55
  • do you need to make some changes on your project when UITextField called? – engmahsa Oct 06 '15 at 12:56

1 Answers1

3

This is not possible to deduce from UIKeyboardDidShowNotification simply because it contains following information only. However, check this SO thread which has a brilliant solution on how to get the current first responder.

NSConcreteNotification 0x7ff14d1ac0d0 {name = UIKeyboardWillShowNotification; userInfo = { UIKeyboardAnimationCurveUserInfoKey = 7; UIKeyboardAnimationDurationUserInfoKey = "0.25"; UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 216}}"; UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 676}"; UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 460}"; UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 568}, {320, 216}}"; UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 352}, {320, 216}}"; UIKeyboardIsLocalUserInfoKey = 1; }}

Community
  • 1
  • 1
Abhinav
  • 37,684
  • 43
  • 191
  • 309