views:

48

answers:

1

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!

A: 

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

Joshua Nozzi
You mean, i should have a NSImageView in the xib? Not just add it programmatically?
eemerge
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
I made the changes, still nothing shows.
eemerge
Please show your code with initWithFrame:
JeremyP
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
Please check the link at the end of the question for a more detailed question on the same subject (posted by me also)
eemerge
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
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