kov*_*pas 132
Objective-C的
[myTextField addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
Run Code Online (Sandbox Code Playgroud)
斯威夫特4
myTextField.addTarget(self, action: #selector(textFieldDidChange(sender:)), for: .editingChanged)
@objc func textFieldDidChange(sender: UITextField) {...}
Run Code Online (Sandbox Code Playgroud)
我解决了改变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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
35259 次 |
| 最近记录: |