NSOutlineView

I’m spending a lot of time now with my new friend, the AppKit object NSOutlineView. Right now I’m trying to implement drag and drop, which is easy if you actually look for the documentation for NSOutlineViewDataSource, which, silly me, isn’t mentioned in the “Drag and Drop Programming Topics for Cocoa.” Instead, the documentation outlines how to create drag and drop for tables–and silly me, knowing that the NSOutlineView inherits from NSTableView, started writing the data methods for table drag and drop instead of outline view drag and drop.

The other thing that is extremely disappointing are NSViewControllers. When I first read about them I thought “oh, cool; the perfect class thingy to insert into the view hierarchy to provide the functional equivalent of a NSWindowController but for just a subclass of the window view hierarchy!”

Uh, no.

First, the NSViewController only exists for 10.5 as far as I can tell–and any application development I want to do should be 10.4 backwards compatible. (Many corporations such as Yahoo! are still using 10.4 internally, as corporations tend to be about one to two years behind in deploying new operating systems.) Second, it seems NSViewController objects are designed to allow and control views that are “out in space”–that is, that are not associated with a window, or that are programmatically associated later on with a window.

To do what I want to do, I simply created a custom class and hooked the responder chain in my class. It’s ugly as hell–but it’s exactly what I want: a way to handle just a subset of controls within a region of my window to properly manipulate the events. (Think of a group of radio buttons or check boxes which change the state of other radio buttons or check boxes in a group box of controls–at a higher level you may just want the abstraction “I’m in state ‘N'”–which translates to some combination of check boxes being enabled or disabled at the lower state. By placing the functionality of translating “N” into the state of a bunch of controls, I’ve isolated key functionality somewhere else–which is, to me, the whole point of object oriented programming: hiding the ugly details in reusable classes.)

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s