0

I'm trying to create a NSImageView programmatically as a subview of another NSImageView when awakeFromNib is called. My code is as follows (Fader is defined in MyImageView.h):

@implementation MyImageView

- (void)awakeFromNib {

Fader = [NSImageView initWithFrame: [self frame]];

}

I get the warning message "NSImageView may not respong to +initWithFrame". When I build, the app simply frizzes without showing anything, and I have to "force quit".

What am I doing wrong?

iUser
  • 1,075
  • 3
  • 20
  • 49
Jaliborc
  • 353
  • 5
  • 16

1 Answers1

1

You’ve forgotten to send +alloc in order to allocate the object. Change that line to:

Fader = [[NSImageView alloc] initWithFrame: [self frame]];
  • Yes, noticed it now too. Thank you for the quick answer. – Jaliborc Apr 23 '11 at 13:38
  • 1
    Also important to note that "Fader" should be "fader" as it's a variable. Class names are capitalized but variables (including instance variables) should begin with lower-case letters by convention. Since the Wide World expects this convention, it makes your code harder to understand *at a glance* when sharing it with others. Conventions are there for universal understanding. :-) – Joshua Nozzi Apr 23 '11 at 14:13