tags:

views:

40

answers:

3

Hi there.

I have an NSView with two views inside of it. I am trying to hide one view and show the other one, but the view won't change.

I tried with setHidden, removeFromSuperview, addSubview in front, everything. The first view is still there and the other one will not show itself. I am doing something wrong?

Thank you, —Albé

+1  A: 

As long as each of the sub views has a connection to it (IBOutlet) then you should be able to use [superView replaceSubview:oldView with:newView];.

theMikeSwan
Oh. You're right. I thought the connections were fine, but I connected the same Outlet with two subviews. Thank you!
Alberto
Don't forget to retain both views (e.g., with a retaining property). If you don't have accessors for each outlet, the nib loader will simply assign the views' pointers to the outlet ivars, and one of the views will die the moment you remove it from the view hierarchy, leading to a crash later on.
Peter Hosey
+1  A: 

In addition to theMikeSwan's suggestion, you could use NSViewAnimation (or a host of other techniques) to animate the transition.

jfm429
A: 

You could also put both views into a tabless tab view, and simply set the selected tab index of the tab view.

Peter Hosey