Eugene Gordin
Eugene Gordin

Reputation: 4107

NSView is not showing up after it was added as a subview (Cocoa/OSX)

In my program I have the following set up:

I have 3 NSViews which I made in the interface builder enter image description here

So PaintView is a subview of PlayerView and ImageView is the view on top of PlayerView.

When the program starts ImageView is hidden. The PaintView is transparent so I see the PlayerView under it but clicking happens on PaintView. So far so good.

Now, what I want to accomplish is that when I press the button, PlayerView becomes hidden, ImageView becomes visible and the PaintView becomes its subview. So I can see the ImageView trough transparent PaintView, but still be able to click on PaintView.

What my approach was so far is something like this:

// on the app start

[ImageView setHidden: YES];

// on the button press
[PaintView removeFromSuperview];
[PlayerView setHidden:YES];
[ImageView setHidden:NO];
[ImageView addSubview:PaintView positioned:NSWindowAbove relativeTo:nil];

Unfortunately, this doesn't give me the desired result. ImageView is on the very top, so I can't click on PaintView.

Does anyone know what am I doing wrong?! Any kind of help is really appreciated!

Thank you!

Upvotes: 2

Views: 1250

Answers (1)

Derek
Derek

Reputation: 1170

removeFromSuperview releases that object and everything that it contains. Check to see if PaintView is nil at the point where you're trying to add it to another view.

Upvotes: 2

Related Questions