Cocoa - 添加后子视图不显示

发布于 2024-09-06 08:15:33 字数 1020 浏览 1 评论 0 原文

我试图向容器添加一些子视图(容器是 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜味拾荒者 2024-09-13 08:15:33

NSView 的指定初始值设定项是 -initWithFrame: ... 没有框架,该视图在其超级视图中的位置在哪里?

The designated initializer for NSView is -initWithFrame: ... without a frame, where is the view in its superview?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文