简体   繁体   中英

How to set the inputDelegate for a UITextField?

I have a UIAlertView containing a UITextField:

UITextField *textField = [alertView textFieldAtIndex:0];

Now I want to set the inputDelegate property for the textField:

[textField setInputDelegate:self];

My view controller (self) conforms to UITextInputDelegate and it has the method

- (void)textDidChange:(id<UITextInput>)textInput;

but for some reason this method is never called when I change the text in the textField. So I assume that my view controller is not set as the textField's inputDelegate.

The documentation states:

The text input system automatically assigns a delegate to this property at runtime. It is the responsibility of the view that adopts the UITextInput protocol to notify the input delegate at the appropriate junctures.

Does that mean that I cannot change the inputDelegate of a text field?

How can I achieve that the textField really calls the delegate method textDidChange: in my view controller whenever its contents change?

I have same experience that inputdelegate will never work.

I have found this page for you,

input delegate

However, to solve your problem, i suggest you use delegate instead!

UITextField *textField = [alertView textFieldAtIndex:0];

textField.delegate = self;

我不知道如何为UITextField设置inputDelegate ,但您可以观察UITextFieldUITextFieldTextDidChange通知 ,以便在文本更改后得到通知。

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