我试图向容器添加一些子视图(容器是 NSView 派生类,子视图是一些 NSImageView 对象)。由于由于尝试了不同的东西,代码现在很混乱,我暂时不会全部粘贴。
这是我添加子视图的部分:
NSImage *tileImage;
tileImage = [[NSImage alloc] initWithContentsOfFile:[textures objectAtIndex:i]];
NSImageView *imageView;
imageView = [[NSImageView alloc] init];
[imageView setImage:tileImage];
[self addSubview:imageView];
NSRunInformationalAlertPanel(@"Count subviews", [NSString stringWithFormat:@"%d",[[self subviews] count]], @"OK", NULL, NULL);
[self setNeedsDisplay:TRUE];
NSRunInformation... 显示 18 (这是我加载的文件的正确数量)。图像没问题,我之前将它们直接显示到容器视图中。
正如我所说,问题是加载后没有显示任何内容。也许我必须做点别的事?
我使用Apple的示例代码COCOASLIDES作为指导,最初我试图加载一个更复杂的子视图(使用在Interface Builder中创建的自定义xib),但也失败了(没有显示)。
也许有人可以指出一些提示、一些指导方针。
谢谢。
重要提示:我已经就该主题提出了一个新问题(与此相关,但更详细且带有源代码),因此每个愿意提供帮助的人请检查此问题:
新问题
谢谢!
Im trying to add some subviews to a container (container is a NSView derived class, and subviews are some NSImageView objects). Since the code is messy right now due to trying different stuff, i wont paste it all for the time being.
This is the part where i add the subviews:
NSImage *tileImage;
tileImage = [[NSImage alloc] initWithContentsOfFile:[textures objectAtIndex:i]];
NSImageView *imageView;
imageView = [[NSImageView alloc] init];
[imageView setImage:tileImage];
[self addSubview:imageView];
NSRunInformationalAlertPanel(@"Count subviews", [NSString stringWithFormat:@"%d",[[self subviews] count]], @"OK", NULL, NULL);
[self setNeedsDisplay:TRUE];
The NSRunInformation... displays 18 (this is the correct number of files im loading). The images are ok, i was displaying them before this directly into the container view.
As i was saying, the problem is nothing is displayed after loading. Maybe i must do something else?
Im using the sample code COCOASLIDES from Apple for guidance , initially i was trying to load a more complex subview (using a custom xib created in Interface Builder),but that also failed (nothing showing).
Maybe someone could point out some hints, some guidelines.
Thanks.
IMPORTANT: I've asked a new question (related to this one, but more detailed and with source code) on the subject, so everyone who would like to help please check this question:
New question
THANKS!
发布评论
评论(1)
NSView 的指定初始值设定项是 -initWithFrame: ... 没有框架,该视图在其超级视图中的位置在哪里?
The designated initializer for NSView is -initWithFrame: ... without a frame, where is the view in its superview?