-1

Is it possible to check if a TextField has been resigned?

I have 3 TextFields, and Cycle through them with return key with (resignFirstResponder) and (becomeFirstResponder)

But is there a way to check if a field has resigned? I noticed some of my app testers don’t use return key but click manually on the fields, and that way my previous field doesn’t save data the way it should.

What’s the best way to check if a user clicked away from a TextField ? Either on to a next text field or temporary away ?

1 Answers1

-1

isFirstResponder Apple Docs

Returns a Boolean value indicating whether this object is the first responder.

var isFirstResponder: Bool { get }

how to use

if txtField.isFirstResponder {
// do whatever you want to
}

If you want to save data when textField change focus .. you should implement delegate method of text field

Before resigning as first responder, the text field calls its delegate’s textFieldShouldEndEditing(_:) method. Use that method to validate the current text.

func textFieldShouldEndEditing(_ textField: UITextField) -> Bool

in your case yo can check which texfield ends editing

func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
   if textField == textfield1 {
     // save 
   }
}

Apple Docs for textFieldShouldEndEditing

Jawad Ali
  • 13,556
  • 3
  • 32
  • 49
  • I’m Looking for resigning first responder? Whenever a field stops being first responder. –  Apr 30 '20 at 19:37
  • 1
    Is it possible to check if a TextField has been resigned.... check if field is first responder or not .... – Jawad Ali Apr 30 '20 at 20:27