Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically changing the contents of a view in an NSSplitView?

I have an application which has a layout similar to iTunes. The main window is an NSSplitView.

Depending on what the user selects in the left column, I need to show a different view. For example, in itunes if you click on "Music" you see a list of songs in a table, if you click on "TV Shows" I see a white screen with some text on it.

Been trying to work this out for ages, any pointers in the right direction would be very handy!

like image 336
Jay Avatar asked Jul 05 '11 13:07

Jay


2 Answers

In the right-hand pane of your NSSplitView you could place a tab-less NSTabView. Each tab of the view could contain one of the views you want to display. Then, in your outline view's delegate, just ask the tab view to display the appropriate view when a particular item is selected.

like image 72
Rob Keniger Avatar answered Oct 16 '22 08:10

Rob Keniger


This is really a job for NSViewController. Using that means you can put each view into a separate nib file and then swap them in and out as needed. When you need to swap the views you can do something like this (assuming you have an NSBox in the right hand pane of the NSSplitView)

NSView *musicView = [musicViewController view];
[rightPaneBox setContentView:musicView];

Edit for a fuller example:

If you have, for example, a Music view and a TV view. You'd create two new nib files, say MusicView.nib and TVView.nib and design your views in those. Then you'd create two subclasses of NSViewController, MusicViewController and TVViewController. In the init method for each of those you'd call [super initWithNib:@"MusicView.nib" bundle:nil].

then in your methods that select the new view, call [musicViewController view] to get a view to place into the right hand side of the NSSplitView.

like image 29
iain Avatar answered Oct 16 '22 09:10

iain