Why does UITextField lock up when setting itself to delegate

前端 未结 3 914
刺人心
刺人心 2021-01-16 02:46

I have a class that extends UITextfield. I also have the same class set to be it\'s own delegate so when the text field is selected I can change the background color. Once I

相关标签:
3条回答
  • 2021-01-16 03:07

    Subscribe to UITextFieldTextDidBeginEditingNotification or UITextFieldTextDidEndEditingNotification NSNotifications. In callbacks check if notification object is self. Then perform some action on it.

    0 讨论(0)
  • 2021-01-16 03:22

    The delegate is always another UIViewController as the events are delegated to it by another class where protocol is defined.

    There's no need of delegate methods in the same class when you can access all the variables and methods in the same class.

    you simply can call [self someFunction].

    As you are inheriting the UITextField , you don't need to define even a property for the UITextField delegate.You just need to set it a different viewController.

    Also the class defining the protocol just has the declaration and it does not conform to the protocol.

    The delegate will be the class which conforms to the protocol.

    0 讨论(0)
  • 2021-01-16 03:22

    The discussion in this question should guide you in the right direction self.delegate = self; what's wrong in doing that?

    0 讨论(0)
提交回复
热议问题