开发者

Subclassing UIBarButtonItem

开发者 https://www.devze.com 2023-03-10 21:29 出处:网络
I\'m trying to make a subclass of the UIBarButtonItem class. The button is added in the nib file and I set its class to my custom class in the interface builder. Now if this was a UIView class or subc

I'm trying to make a subclass of the UIBarButtonItem class. The button is added in the nib file and I set its class to my custom class in the interface builder. Now if this was a UIView class or subclass I would have override the - (id)initWithCoder:(NSCoder *)decoder method to start the extra customization, however UIBarButtonItem lacks开发者_StackOverflow such a method. I tried to override its -(id)init method but with no success, it doesn't get called. My question, where should I start my customization? What method do I need to override?


It's because you use IB. When you create an object in IB it does not call the init method for the class, it uses the archive version of the object. So to make custom initializations use this method instead:

-(void)awakeFromNib{
    //initialize here
}
0

精彩评论

暂无评论...
验证码 换一张
取 消