ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  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. Override add?
    2004-08-01 00:32:42  donarb [View]

1 to 1 of 1