self.delegate = self; what's wrong in doing that?

前端 未结 1 421
栀梦
栀梦 2020-11-30 10:38

self.delegate = self; what\'s wrong in doing that? and what is the correct way of doing it?

Thanks, Nir.

Code:

(UITextField*)initWi         


        
相关标签:
1条回答
  • 2020-11-30 11:12

    See this thread

    http://www.cocoabuilder.com/archive/cocoa/241465-iphone-why-can-a-uitextfield-be-its-own-delegate.html#241505

    Basically, the reason for the "freeze" when you click on your UITextField with itself as a delegate is that respondsToSelector is calling itself -> infinite recursion.

    UITextField is unique AFAIK. You can usually use a class as its own delegate with no particular problems. For UITextField you must create an actual delegate (that could, of course, call methods on the UITextField for which it's a delegate. Just be careful to avoid retain loops, even if you're using ARC).

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