Coding Tips #1: UIBarButtonItem Subclasses, Quick Documentation Access
-
Tip: Do not use -init as class initializer when subclassing UIBarButtonItem because it WILL cause an infinite loop. This one took a while for me to debug.
I had setup a custom UIButton to serve as the custom view for my UIBarButtonItem subclass, and was calling [super initWithCustomView:]. Turns out that initWithCustomView will call [self init], which I had overwritten, so it would call [super initWithCustomView:], and just start an infinite loop.
Point-in-case, do NOT use -init as your class initializer when you subclass UIBarButtonItem. Feel free, however, to create your own class convenience method that does all this work for you and calls -initWithCustomView:
- Xcode Pro-Tip: Option-double-clicking on a method will bring up a documentation HUD if documentation is available for that method. It’ll give you a brief description of what the method does, parameters it accepts, sample code related to it, and more.