如何才能在文本字段的内容发生变化时调用函数?
发布于 2013-01-26 05:30:29
实际上,没有UITextField
的值更改事件,请使用UIControlEventEditingChanged
发布于 2013-11-11 23:31:36
我解决了更改shouldChangeChractersInRange行为的问题。如果您返回NO,更改将不会由iOS在内部应用,而是您有机会手动更改,并在更改后执行任何操作。
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
//Replace the string manually in the textbox
textField.text = [textField.text stringByReplacingCharactersInRange:range withString:string];
//perform any logic here now that you are sure the textbox text has changed
[self didChangeTextInTextField:textField];
return NO; //this make iOS not to perform any action
}
发布于 2016-07-19 15:02:00
对斯威夫特来说,这很方便-
textField.addTarget(self, action: #selector(onTextChange), forControlEvents: UIControlEvents.EditingChanged)
https://stackoverflow.com/questions/4006137
复制相似问题