Create subview on awakeFromNib
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 de开发者_JAVA百科fined 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?
You’ve forgotten to send +alloc
in order to allocate the object. Change that line to:
Fader = [[NSImageView alloc] initWithFrame: [self frame]];
精彩评论