I am trying to make a cocoa app with an NSplitView that keeps track of "active subviews" (like how the Terminal app knows which pane you are editing).
I have a SessionWindowController that keeps track of the "currentPaneContainerViewController" based on which PaneView the user last clicked on.
some classes and files:
SessionWindowController.h/.m
PaneContainerViewController.h/.m
PaneView.h/.m
PaneContainerView.xib
PaneContainerView.xib has the PaneContainerViewController as its file owner.
My current implementation is as follows:
To access the PaneContainerViewController from the NSView, I use IBOutlets that reference to the file owner, and to access the SessionWindowController I also maintain an IBOutlet of the object conforming to a delegate method I made (namely, the object happens to be the SessionWindowController).
#import <Cocoa/Cocoa.h>
#import "PaneViewDelegate.h"
@class PaneContainerViewController;
@class SessionWindowController;
@interface PaneView : NSView
{
//outlet connection to own controller
IBOutlet PaneContainerViewController *myPaneContainerViewController;
//we'll use delegation to get access to the SessionWindowController
IBOutlet id<PaneViewDelegate> sessionDelegate;
}
@implementation PaneView
-(void)mouseUp:(NSEvent *)event
{
if (sessionDelegate && [sessionDelegate respondsToSelector:@selector(setCurrentPaneContainerViewController:)]) {
[sessionDelegate setCurrentPaneContainerViewController:myPaneContainerViewController];
}
}
Here is the class that sessionDelegate belongs to, which conforms to the PaneViewDelegate protocol:
@interface SessionWindowController : NSWindowController <PaneViewDelegate>
{
PaneContainerViewController *currentPaneContainerController;
}
- (void)setCurrentPaneContainerViewController:(PaneContainerViewController*)controller;
My trouble is accessing the SessionWindowController object using the IBOutlet. In Interface Builder, what do I connect the sessionDelegate outlet to to be able to access the SessionWindowController instance? Furthermore, is it okay to pass the controller to the delegate instead of an NSEvent?
I am new to Cocoa, so if there is a better design pattern do please let me know. This does seem like a lot of boilerplate for a pretty common functionality.