私が実装しようとしているのは、UITextField
単語を文字として見る です。具体的には、たとえば、数式 sin( を 1 文字として表示しようとしています。独自の UITextInputDelegate を実装することでこの問題を解決しようと考えました。ただし、このプロトコルを実装または採用すると、このプロトコルから必要な 4 つの関数が呼び出されません。次の方法で実装しようとしました。
a をサブクラス化することによってUITextField
。
@interface BIDUItextFieldDelegate : UITextField < UITextInputDelegate >
NSObject をサブクラス化する。
@interface BIDTextfieldInputDelegate : NSObject < UITextInputDelegate >
対応する .m ファイルには次が含まれます。
@implementation BIDTextfieldInputDelegate
- (void)selectionWillChange:(id <UITextInput>)textInput
{
NSLog(@"sWill");
}
- (void)selectionDidChange:(id <UITextInput>)textInput
{
NSLog(@"sDid");
}
- (void)textWillChange:(id <UITextInput>)textInput
{
NSLog(@"tWill");
}
- (void)textDidChange:(id <UITextInput>)textInput
{
NSLog(@"tDid");
}
たとえば、2 番目のアプローチ (NSObject のサブクラス化による) の場合、アプリ内に表示される追加のカスタム UITextfield クラスの (id) init メソッドで次のことを行います。
//textInputDel is an instance of the custom NSObject class that adopts the above UITextInputDelegate protocol
self.textInputDel = [[BIDTextfieldInputDelegate alloc] init];
self.inputDelegate = self.textFieldDel;
誰かが私が間違っていることを知っているか、より良い解決策を持っていますか?