skip to Main Content

so i make this func which is triggered when 2 textfield reach minimum amount of text count will make the button is enabled.

it works on ios 13 and above but it wont work on ios 12….which i dont know how and why it wont work

so basicly my textFieldDidChangeSelection doenst trigger anything when i type on my textfield…..its not working on ios 12 but its working on 13 an above

i try to put some print on textFieldDidChangeSelection but nothing is print on console

this is my code

//this is my func code

func buttonReady() {
    if phoneNumberTextField.text!.count > 8 &&   textPinTextField.text!.count == 6{
          loginButton.isUserInteractionEnabled = true
          loginButton.backgroundColor = UIColor.init(string:    COLOR_RED)
          loginButton.setTitleColor(UIColor.white, for: .normal)
          print("ahaaaa 🏌🏻")
      } else {
          loginButton.isUserInteractionEnabled = false
          loginButton.backgroundColor = UIColor.init(string: COLOR_GREY_BUTTON)
          loginButton.setTitleColor(UIColor.init(string: COLOR_GREY_TEXT), for: .normal)
          print("hmmmm 🤔")
      }
  }

and i use that func in here

func textFieldDidChangeSelection(_ textField: UITextField) {
    if textField == phoneNumberTextField {
        buttonReady()
        
    }
    if textField == textPinTextField {
        buttonReady()
        
    }
    
}

and here

override func viewDidLoad() {
    super.viewDidLoad()
    
    // Do any additional setup after loading the view.
    
    buttonReady()
    hideKeyboardWhenTappedAround()
}

and im using SkyFloatingLabelTextFIeld for my custom textfield

i still dont get it why that func couldnt work on ios12 while it works on ios 13 and above

2

Answers


  1. Same question

    You can try this

        override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        phoneNumberTextField.addTarget(self, action: #selector(textFieldDidChange), for: .editingChanged)
        textPinTextField.addTarget(self, action: #selector(textFieldDidChange), for: .editingChanged)
        buttonReady()
        hideKeyboardWhenTappedAround()
    }
    

    than

        @objc func textFieldDidChange() {
        buttonReady()
    }
    
    Login or Signup to reply.
  2. Check out UITextField.h, you’ll see:

    - (void)textFieldDidChangeSelection:(UITextField *)textField API_AVAILABLE(ios(13.0), tvos(13.0));
    

    textFieldDidChangeSelection is only available on iOS 13.0 and greater.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search