0

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!

Community
  • 1
  • 1
eemerge
  • 75
  • 2
  • 9
  • Duplicate of [Cocoa - loading a view from a nib and displaying it in a NSView container , as a subview](http://stackoverflow.com/questions/3083740/cocoa-loading-a-view-from-a-nib-and-displaying-it-in-a-nsview-container-as-a) (OP posted a "clarification" as a new question) – Joshua Nozzi Jun 21 '10 at 14:02

1 Answers1

1

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

Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135
  • You mean, i should have a NSImageView in the xib? Not just add it programmatically? – eemerge Jun 20 '10 at 23:24
  • No, I mean you should use initWithFrame: instead of -init when creating your NSImageView if you choose to do it programmatically. Give it a frame that makes sense within the bounds of the intended superview. – Joshua Nozzi Jun 21 '10 at 01:23
  • NSImageView *imageView; imageView = [[NSImageView alloc] initWithContentsOfFile:[textures objectAtIndex:i]]; imageView = [[NSImageView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]; [imageView setImage:tileImage]; [self addSubview:imageView]; sorry i cant format it nicely... – eemerge Jun 21 '10 at 09:13
  • Please check the link at the end of the question for a more detailed question on the same subject (posted by me also) – eemerge Jun 21 '10 at 10:14
  • Don't create new questions just to clarify old ones. That makes a mess and doesn't earn you a very good reputation on SO. – Joshua Nozzi Jun 21 '10 at 14:00
  • Sorry, i just thought a more complete example with full code source would be easier for people to understand what i want and offer their ideeas. I realize it might be a little bit confusing but i was just trying to be more explicit to what my problem is. Also, i think even my 2 questions are related, they can be taken as separate issues: this one, adding a NSImageView programatically, and the other one, loading a view from a nib/xib. In the future i'll try to avoid this kind of duplicate questions :) – eemerge Jun 21 '10 at 15:36