• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: re-factoring a category into a class instance
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: re-factoring a category into a class instance


  • Subject: Re: re-factoring a category into a class instance
  • From: Brian Stern <email@hidden>
  • Date: Tue, 10 Jun 2008 18:04:09 -0400


On Jun 10, 2008, at 5:05 PM, Paul Archibald wrote:

Comrades:

I am working on a file-handling Cocoa app that (at this point) has a single window. We are adding a second window (really sort of a non- modal dialog) to do some extra processing of the target files. The interface for the new window is already built (with IB), but is not hooked up yet.

So, the way this started was as a AppController(ExtraCategory) thing, with the NIB file having a single controller object. I don't like that method, because there is a lot of data and code that would need to be replicated in the main AppController to handle the work that the ExtraCategory does. What I would like to do is put all the ExtraCategory stuff into its own class, but I am not sure how. My inclination is toward making the ExtraCategory into a NSWindowResponder, but the documentation I have read so far makes it look like that is more intended for document-based apps, which this is not. Also, I don't quite see (looking at some example code) how an extra controller is instantiated by the main app controller.


Since there's no such thing as NSWindowResponder I assume what you meant was NSWindowController. And that's what you should use. There's no limitation of NSWindowController being only available or useful in document based apps.


You can instantiate it in the nib with IB or in code. I usually instantiate it in code and have it load the nib and be the file's owner.

@implementation MyWinController

- (id)initWithWhatever:(whatever*)whatever
{
self = [super initWithWindowNibName:kMyWindowNibName];
if (self) {
// Add your subclass-specific initialization here.
// If an error occurs here, send a [self release] message and return nil.
}
return self;
}


// etc.


// instantiate it in your app controller something like this:

- (void)showMyWindow
{
if (! mMyWinController)
{
mMyWinController = [[MyWinController alloc] initWithWhatever:whatever];
}

[mMyWinController showWindow:self];
}




_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >re-factoring a category into a class instance (From: Paul Archibald <email@hidden>)

  • Prev by Date: Re: NSSlider responding to superview's drawRect
  • Next by Date: Re: Prevent Asynchronous operation of beginSheetModalForWindow
  • Previous by thread: re-factoring a category into a class instance
  • Next by thread: Re: re-factoring a category into a class instance
  • Index(es):
    • Date
    • Thread