On 7 Nov 2013, at 5:46 pm, Joseph Ayers <j.ay...@neu.edu> wrote:

> I’m working on a program that does digital signal processing on the audio 
> tracks of a Quicktime Movie. 
> 
> I have a NSWindow that has a NSTabView. The window has some drawers that open 
> when one of the tabs is clicked on. One of the tabs draws a digital 
> oscilloscope, another draws graphs and a third some DSP graphics The drawers 
> contain  NSView's with text boxes for parameters of the graphics and 
> checkboxes for graphic features.

First, I’d say that using drawers these days is considered a bit old-fashioned, 
especially for primary UI, but that’s up to you of course; they’re still 
supported.

> As each view has a NSViewController, I’m having troubles finding examples of 
> how I construct an appropriate nib. For example. The graphics view has 
> several boolean flags and scalars that control aspects of the graphs and 
> these properties are associated with the graphics NSView. The corresponding 
> drawer has check boxes for the booleans and text boxes for the scalars and 
> has it’s own NSView and NSViewController. When I hook up these outlets for 
> the NSViewController so their targets are the properties in the NSView, they 
> don’t work.
> 
> My fundamental conundrum is that the NSViews for the graphics are associated 
> with NSTabViewItems and these do not appear to be supported in Xcode 5 
> interface builder. If I tell a generic object that it’s a NSTabViewItem it 
> does not expose a view outlet. Moreover, how one associates a 
> NSVIewController with a NSTabViewItem is a bit confounding.
> 
> Can someone point me to some sample code or documentation that deals with 
> these issues?


If you are using NSViewController, typically that will be associated with a 
separate nib for the view it controls. That can make sense for views that take 
up a lot of memory but are only needed occasionally - you avoid loading the 
view unless it’s needed. But the downside is that being a separate nib, you 
have to do some work to load it at the appropriate time - there’s no support in 
Mac OS and IB on Mac to indirectly specify that a view (e.g. a subview of a tab 
view) is loaded from another nib.

In the scenario you outline, I’d suggest that the use of NSViewController is 
not going to give you anything worthwhile. Instead, just declare your own 
controller classes that are subclasses of NSObject, one for each of the tab 
views you want. Then, you can lay out all of the views directly in IB, and add 
the controllers as objects to that nib, and wire up all their outlets and 
actions. You’ll probably want to make a master controller (typically a 
NSWindowController subclass set as File’s Owner for the nib) that has outlets 
to each subcontroller.

The way to add subviews to a NSTabView is to simply drag the views to the tab’s 
content area in IB, as I said you have no way on Mac to specify another view 
controller to be loaded into that tab. So by not bothering with 
NSViewController at all, you’ll probably find it’s all a lot easier.

If you can’t let go of the idea of using NSViewControllers, you’ll have to 
write code that detects which tab has been selected, and map its index or 
identifier to the name of the nib containing its content views, and instantiate 
the view controller yourself using the nib name you calculated. Then you can 
assign that controller to some local ivar to talk to the controller and hence 
the controls/views it manages. What have you gained writing all this extra 
code? Nothing really, and what you’ve lost is the ability to lay out the 
controls/views in the tab view they actually belong to.

—Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to