简体   繁体   中英

How to do an event when uitext field is being typed

如何在UITextField中键入时执行操作?

First set your UITextField's delegate to your class.

If you want to call an event as soon as user types anything implement this method,

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
     NSLog(@"call your method");
    [self goMethodCall];
    return YES;
}

If you want somthing other than this, you have few more delegates.

There are few delegates that are invoked automatically...

– textFieldShouldBeginEditing:
– textFieldDidBeginEditing:
– textFieldShouldEndEditing:
– textFieldDidEndEditing:
– textField:shouldChangeCharactersInRange:replacementString:
– textFieldShouldClear:
– textFieldShouldReturn:

In any of the method call your action.

Find suitable for you.. here

There are several ways to be notified when the text of a text field has changed:

  1. Implement the UITextField delegate method textField:shouldChangeCharactersInRange:replacementString:
  2. Register for the UITextFieldTextDidChangeNotification notification.
  3. Add an action/target for the UIControlEventEditingChanged control event on the text field.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM