• 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
View controllers (was Re: Garbage collection, leaks and drains)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

View controllers (was Re: Garbage collection, leaks and drains)


  • Subject: View controllers (was Re: Garbage collection, leaks and drains)
  • From: Chris Hanson <email@hidden>
  • Date: Thu, 3 Jan 2008 19:11:12 -0800

On Jan 3, 2008, at 11:03 AM, Ben wrote:

Most of these views are in separate nib files and their file's owner is a similarly named class (for example GroupView.nib has GroupViewManager.h/m).

Bill already addressed your GC concerns, but I thought this would be a good example of the use of another new Leopard Cocoa feature, NSViewController. The point of an NSViewController is to act as the owner of an "independent" view hierarchy, just like you're doing with your ViewManager classes.


NSViewController Class Reference
<http://developer.apple.com/documentation/Cocoa/Reference/NSViewController_Class/Introduction/Introduction.html >


What I do is create an application-specific base class that derives from NSViewController (call it MyAppViewController) that implements an -init method like this:

- (id)init {
return [super initWithNibName:[self nibNameForClassName]
bundle:[NSBundle bundleForClass:[self class]]];
}


I also implement a -nibNameForClassName method that gets the name of the current class and lops off "Controller" (and possibly my custom prefix, too) so that I don't litter my code with nib names; instead, they're inherent in the class name.

One other thing I find it useful to do when subclassing NSViewController is override -loadView to implement pre/post-load hooks like NSWindowController has:

- (void)viewWillLoad {
    // Here for subclasses to override.
}

- (void)viewDidLoad {
    // Here for subclasses to override.
}

- (void)loadView {
    [self viewWillLoad];
    [super loadView];
    [self viewDidLoad];
}

These hooks have come in handy occasionally. There's also - awakeFromNib, of course, but I generally try to only implement things- I-wish-I-could-do-in-IB in that method (e.g. setting the double action of a table view), and perform more controller-level operations (such as telling a data source to fetch model objects) in a - {window,view}DidLoad method.

  -- Chris

_______________________________________________

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: 
 >Garbage collection, leaks and drains (From: Ben <email@hidden>)

  • Prev by Date: Re: Questions about enhancing the Learn Cocoa II app.
  • Next by Date: NSUndoManager invalid state
  • Previous by thread: Re: Garbage collection, leaks and drains
  • Next by thread: SBApplication taking forever to instantiate
  • Index(es):
    • Date
    • Thread