• 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: Best data source for table view in document window
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best data source for table view in document window


  • Subject: Re: Best data source for table view in document window
  • From: Kyle Sluder <email@hidden>
  • Date: Wed, 05 Sep 2012 08:24:56 -0700

On Sep 5, 2012, at 5:39 AM, Jerry Krinock <email@hidden> wrote:

> What is the best the data source for a table view in a document window?  The candidates are…
>
> (1)  Category of the document.  This is the way it is done in the WithoutBindings ("With and Without Bindings") Apple sample code.  But it seems like too much "view-ish" code in the data model, particularly when my document class is also used in a GUI-less command-line tool, which has no need for this code.

NSDocument is really a controller. But if you already have a window controller subclass, then putting UI things in the document is kind of unnecessary.

>
> (2)  Separate, standalone object.  Fancy housekeeping is needed to avoid retain cycles, and crashes in corner cases as the document window is closing.

Quite common. This kind of life cycle management is part of living with Cocoa.

Consider making this object an NSViewController subclass.

>
> (3)  Category of the window controller.  Probably not a bad choice, except that my window controller for this multi-tabbed window is already huge.

I start here and then move to #2 if the window controller gets too big.

>
> (4)  Category of the table view itself, assuming that it is subclassed.  Seems like a logical division.  No worrying about whether table view or its data source gets deallocced first.  Access the document via [[[self window] windowController] document].

Absolutely, completely, 100% not. Never ever do this. If NSTableView privately implements any methods that it also expects the data source to implement, you will get bad behavior. This happened to someone using UITableView on this list a few years ago. Plus using window] windowController] document] is a terrible design.

--Kyle Sluder
_______________________________________________

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


  • Follow-Ups:
    • Re: Best data source for table view in document window
      • From: Andy Lee <email@hidden>
References: 
 >Best data source for table view in document window (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: Best data source for table view in document window
  • Next by Date: NSButton Action Binding with "self"
  • Previous by thread: Re: Best data source for table view in document window
  • Next by thread: Re: Best data source for table view in document window
  • Index(es):
    • Date
    • Thread