views:

319

answers:

3

All I need to do is load and swap some nibs in a NSView of a window. I know how to do it with NSViewController and have it working perfectly with 10.5-10.6, but I don't know what to do for 10.4.

Tutorial links very welcome, I have trouble finding legacy stuff.

(Yes, I really do need to support 10.4.)

+1  A: 

Basically, you write your own controller class that does the same things that NSViewController does. The controller classes were added to the AppKit because so many of us were writing essentially the same code over and over.

NSResponder
I was told there is one out there on one of the Cocoa dev sites, but I couldn't find it...
zekel
+2  A: 

Use NSBundle to load the nib:

YourController *controller = [[YourController alloc] init];
BOOL success = [NSBundle loadNibNamed:@"YourNibName" owner:controller];
ianh
Looks like loadNibName:owner is a class method, not an instance method.
zekel
You're right; I edited the answer to be more correct.
ianh
+2  A: 

From working with NSViewController in Leopard, I can tell you that its functionality is very basic, and that you should be able to replicate it with fairly minimal effort.

Essentially, it has a view property/outlet, and an initWithNibName:bundle: method. Beyond that, it doesn't do anything especially fancy. It has some convenience things, like adopting NSEditor, and a representedObject property. You should be able to bang out an equivalent class in an hour or two.

Now, what you will give up if you do this is compatibility with later versions of Cocoa. Eventually, you'll probably drop 10.4 support and you'll be left with your class and the real NSViewController. When that happens, I'd recommend re-basing your custom view controller on Cocoa's NSViewController. If you've named the properties with the same names/data types as NSViewController, you should only have to drop the properties and methods you've declared yourself.

Alex