How can I get a textDidChange (like for a UISearchBar) method for a UITextField?

后端 未结 7 817
不知归路
不知归路 2020-12-17 15:23

How can I get a textDidChange method for a UITextField? I need to call a method every time a change is made to a text field. Is this possible? Thanks!

7条回答
  •  情书的邮戳
    2020-12-17 16:01

    Swift Solution

    func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
        let newString = (textField.text as NSString).stringByReplacingCharactersInRange(range, withString: string)
        return true
    }
    

提交回复
热议问题