The Cocoa Controller Layer
Subject:   Override add?
Date:   2004-07-05 14:19:11
From:   markstone1
Response to: Override add?

I just worked out a pretty easy way to set the title/author of newly created books. Hope it helps:

First, subclass NSArrayController in Interface Builder. Nmae it something like MyController. Also, create the files for the new class in your project.
Next, select the BookController instance that was created before and change its 'custom class' to MyController.
Go back to Xcode. Add the following line to MyController.h (it doesn't really matter, but I got a compiler warning otherwise):
#include "Book.h"
Now, override the -(id)newObject: method in MyController.m as follows:

- (id)newObject
id newBook = [super newObject];
[newBook setTitle: @"Unknown Title"];
[newBook setAuthor: @"Unknown Author"];
return newBook;

Just drag MyController.h into IB, save everything and compile!

1 to 1 of 1
1 to 1 of 1