How to display a subview loaded from a separate NIB file
Posted
by Marcus Netter
on Stack Overflow
See other posts from Stack Overflow
or by Marcus Netter
Published on 2010-06-02T01:29:30Z
Indexed on
2010/06/02
1:33 UTC
Read the original article
Hit count: 424
I'm developing a Cocoa desktop application that uses a source list in the style of iTunes: different elements in the source list cause the main content area to display different views.
The content area is entirely filled with a (vertical) NSSplitView
; on the left is an NSOutlineView
source list. When the user selects an item on the left, the relevant view appears on the right side of the splitter.
I can make it work well enough by putting everything in one NIB file and putting a borderless NSTabView
to the right of the splitter; to switch views, I just have to change the selected tab. But putting all the views in one NIB is bad practice, so I'm trying to move each of the subviews into their own NIB files.
I have a pretty good idea of most of this process — I've created an NSViewController
subclass for each of these views (EntityDetailViewController
, GroupDetailViewController
, and so on), set the File's Owner of each new NIB to the relevant controller class, set the view
connection in each NIB, and reworked the bindings. What I don't know is how to actually change which subview is being shown on screen.
I've tried using the default generic NSView
on the right side and sending it addSubview:
messages; I've tried connecting to it as the first subview and calling
NSView *newSubview = /* get subview from the new subview controller */
[[subview superview] replaceSubview:subview with:newSubview];
[self setSubview:newSubview];
But everything just leaves the space blank. How do I display a subview loaded from a separate NIB?
© Stack Overflow or respective owner