How do I check when a UITextField changes?

后端 未结 19 2985
情话喂你
情话喂你 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:34

    Maybe use RxSwift ?

    need

    pod 'RxSwift',    '~> 3.0'
    pod 'RxCocoa',    '~> 3.0'
    

    add imports obviously

    import RxSwift
    import RxCocoa
    

    So u have a textfield : UITextField

    let observable: Observable = textField.rx.text.asObservable()
    observable.subscribe(
                onNext: {(string: String?) in
                    print(string!)
            })
    

    U have other 3 methods..

    1. onError
    2. onCompleted
    3. onDisposed
    4. onNext

提交回复
热议问题