Trying to find which text field is active ios

后端 未结 7 2322
Happy的楠姐
Happy的楠姐 2020-12-28 14:26

I am trying to find which textfield is active for when the I move the view when the keyboard rises. I am trying to set a property in my viewcontroller from the subview of a

相关标签:
7条回答
  • 2020-12-28 15:27

    assuming your textfields are all the same (i.e. all currency or text) and do not require any special formatting, I would suggest the following:

    First, have an optional textField variable. For example:

    var currentTextField: UITextField?
    

    Then add the following:

    func textFieldDidBeginEditing(textField: UITextField) {
    
            currentTextField = textField
    
    }
    

    Now you can do whatever you want with the 'active' text field and you do not need to track any tags unless you need some specific formatting operation.

    0 讨论(0)
提交回复
热议问题