How do I check when a UITextField changes?

后端 未结 19 3144
情话喂你
情话喂你 2020-11-22 15:44

I am trying to check when a text field changes, equivalent too the function used for textView - textViewDidChange so far I have done this:

  fu         


        
19条回答
  •  执笔经年
    2020-11-22 16:17

    Just in case you are interested in a SwiftUI solution, this it's working for me:

     TextField("write your answer here...",
                text: Binding(
                         get: {
                            return self.query
                           },
                         set: { (newValue) in
                            self.fetch(query: newValue) // any action you need
                                    return self.query = newValue
                          }
                )
      )
    

    I have to say it's not my idea, I read it in this blog: SwiftUI binding: A very simple trick

提交回复
热议问题