开发者

Create subview on awakeFromNib

开发者 https://www.devze.com 2023-02-28 19:57 出处:网络
I\'m trying to create a NSImageView programmatically as a subview of another NSImageView when awakeFromNib is called.

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]];
0

精彩评论

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

关注公众号