UITextInputDelegate methods not functioning correctly

前端 未结 2 1310
故里飘歌
故里飘歌 2020-12-31 08:04

I\'m working on iOS 8 custom keyboard extension right now, and there are some issues in using UITextInputDelegate Methods.

Does this right: selectionWil

2条回答
  •  粉色の甜心
    2020-12-31 09:01

    I had the same problem with the functions specified in the UITextInput protocol not being called. The reason as far as I can discern is due to the fact that the inputDelegate is set at runtime. According to the ios docs:

    The UIKit provides a private text input delegate, which it assigns at runtime to the inputDelegate property of the object whose class adopts the UITextInput protocol. link

    The fix which works in my case is to reset the inputDelegate in the function:

    textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range
         replacementString:(NSString *)string
    

    by the following line:

    [myUITextField setInputDelegate:self];
    

    where self implements the UITextInputDelegate protocol.

提交回复
热议问题