Saturday, 14 September 2013

How can I dynamically modify a subview from another view?

How can I dynamically modify a subview from another view?

Let me explain my problem in the context of the program I'm working with.
This program consists of one main window which has an NSOutlineView and an
NSTabView. The NSTabViewItems (and their corresponding subview) are added
dynamically at runtime (using Cmd+T). The aforementioned subview is part
of a separate XIB file; the subview consists of various simple input
controls. All of this works as I've just described.
I want the NSOutlineView to offer context menus for the various items it
is displaying which may manipulate some of the controls within the
currently active NSTabViewItem's subview.
The most obvious way that I see to do this is (this is just a simplified
example, not my actual code):
NSOutlineViewSubclass.h
@interface ... : NSOutlineView
@property (weak) IBOutlet NSTabView *tabView;
@end
NSOutlineViewSubclass.m
@implementation ...
@synthesize tabView;
- (void)foo
{
NSTabViewItem *currentTab = [tabView selectedTabViewItem];
TabViewSubView *tabViewSubView = [currentTab view];
//
//Manipulate subview controls here
//
}
@end
This seems like it violates the MVC paradigm, since I am manipulating data
directly in the view (in this case, NSOutlineViewSubclass), rather than
going through a controller. But, for now, the only time I use the
NSOutlineViewSubclassViewController is to spawn a new view for a new tab
in the first place. My NSOutlineViewSubclass doesn't even know about it's
NSOutlineViewSubclassViewController. Did I miss a step here in connecting
these two?
Thanks!

No comments:

Post a Comment