Reputation: 2149
I have a layering problem with two existing buttons and a NSImageView. I have a custom view called PhotosView which inherits from NSView with two buttons (arrows):
@interface PhotosView : NSView
- (void)setPhoto:(NSURL *)path;
@end
In the implementation of the setPhoto method I add a photo to the PhotosView:
- (void)setPhoto:(NSURL *)path
{
[imageView removeFromSuperview];
imageView = [[NSImageView alloc] initWithFrame:[self frame]];
[imageView setImage:[[NSImage alloc] initWithContentsOfURL:path]];
[self addSubview:imageView];
}
The imageView gets added on top of the two buttons. In my research I only found similar problems to iOS-development. The one helpful thread is here: http://www.cocoabuilder.com/archive/cocoa/55873-nsview-subviews-ordering.html, but I can't really believe there isn't an easier solution?
Upvotes: 0
Views: 78
Reputation: 16354
Change your last line to:
[self addSubview:imageView positioned:NSWindowBelow relativeTo:nil];
(See the API here)
Upvotes: 2