Reputation: 5344
I have created a class derived from NSImageView. However, the classes's constructor (init) is not being called, therefore I'm guessing init is not the correct initializer for NSImageView.
What is the correct initializer for NSImageView? I checked out the manuals but they don't seem to mention the correct init function. A google search doesn't seem to provide any concrete results either.
I have found a possible constructor:
-(id) initWithFrame:(NSRect)frameRect
but I'm not sure if this would be the correct one to call. I'm not too sure what a frameRect is.
What would be the default initializer/constructor for NSImageView? Note I am developing a desktop app not an iOS app if that makes a difference.The NSImageView subclass object has been placed in the window through Interface Builder, not programmatically.
Upvotes: 1
Views: 581
Reputation: 122391
Classes derived from NSView
can be initialised programmatically using initWithFrame
or when loaded from a NIB file using awakeFromNib
. What I do is call a common, private, method to perform initialisation, regardless of how they were loaded:
// Private methods
@interface MyViewSubclass ()
- (void)_setupView;
@end
@implementation MyViewSubclass
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self != nil)
{
[self _setupView];
}
return self;
}
- (void)awakeFromNib
{
[self _setupView];
}
// Common initialisation (called by initWithFrame: and awakeFromNib).
- (void)_setupView
{
// Set stuff up
}
Upvotes: 4
Reputation: 9768
If it's from a nib/xib, initWithCoder:
-(id)initWithCoder:(NSCoder *)coder
Upvotes: 1