Reputation: 77636
What is the proper way of initializing CustomToolbar In code so that my class uses the nib file?
I already have written the code to do that but i know it's not the correct way and it has a leak.
@interface CustomToolbar : UIToolbar {
}
@property (nonatomic, retain) IBOutlet UIBarButtonItem *button;
@end
@implementation CustomToolbar
- (id)initWithDelegate
{
NSArray *objects = [[NSBundle mainBundle]
loadNibNamed:@"CustomToolbar"
owner:nil
options:nil];
if (self = (CustomToolbar*) [objects objectAtIndex:0])
{
//do some work here
}
return self;
}
@end
Upvotes: 0
Views: 1155
Reputation: 2219
The NIB will call initWithCoder:
on your custom class, like this:
- (id)initWithCoder:(NSDecoder*)aDecoder {
self = [super initWithCoder:aDecoder];
if( self ) {
// Do something
}
return self;
}
If you really want to load it the way you do now, you need to retain
the object returned from loadNibNamed
.
Upvotes: 1