• 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: Problems with loose ViewController coupling and KVO to-many relationships
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems with loose ViewController coupling and KVO to-many relationships


  • Subject: Re: Problems with loose ViewController coupling and KVO to-many relationships
  • From: "Jonathan del Strother" <email@hidden>
  • Date: Tue, 7 Oct 2008 11:03:56 +0100

On Tue, Sep 30, 2008 at 8:19 PM, Jonathan del Strother
<email@hidden> wrote:
> Heya
> I'm struggling a bit with NSViewControllers.  My app displays a list
> of widgets.  I have a Widget model, a WidgetView view (an NSView
> subclass), and a WidgetViewController (an NSViewController subclass).
> All of those have a one-to-one mapping - for any given
> WidgetViewController, it has a representedObject pointing to the
> Widget, and a view pointing to the WidgetView.  The user can
> add/remove/reorder the widgets at any time.
>
> So, there's an array of Widgets, which the window controller observes,
> and whenever that array changes, it creates/deletes
> WidgetViewControllers (and inserts WidgetView subviews) to match.  So
> far so good.
>
> (In fact, if I give the Widget model a strong relationship to the
> WidgetViewController (ie the Widget retains its view controller), it
> works perfectly.  Unfortunately, that totally ignores the nice fluffy
> ideal of MVC separation.)
>
> There's a design flaw here somewhere, but I can't quite figure out
> what it is.  It's highlighted by trying to reorder widgets.  With KVC
> to-many relationships, there's no atomic way of moving an object from
> one position in an array to another : you remove the object, then
> re-insert it at the new location.  But when the object is
> (temporarily) removed from the array, the window controller gets an
> observeValueForKeyPath saying it's been deleted, and so releases the
> corresponding WidgetViewController, the view gets deallocated, and so
> on.  I'll then get a second observeValueForKeyPath saying that an
> object has been inserted, recreate the WidgetViewController, re-insert
> the view, etc etc.
>
> This seems pretty wrong to me.  I can see a few workarounds (perhaps
> storing the kvo notifications until the end of the current runloop so
> I can add them together and figure out what was really a deletion and
> what was just a reordering), but they all seem pretty ugly and
> heavyweight.
>
> How is this usually handled?  How do you managed your view controller
> lifetimes w.r.t. the model lifetime?
>
> Thanks for reading this far, any suggestions would be greatly appreciated
> -Jonathan
>


No takers, then?  Anything I could clarify?
_______________________________________________

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

  • Prev by Date: Re: comparing Strings.
  • Next by Date: Re: Getting NSTimer to work after an NSThread completes?
  • Previous by thread: Re: CoreData: Fetching object with maximum of property
  • Next by thread: Re: Problems with loose ViewController coupling and KVO to-many relationships
  • Index(es):
    • Date
    • Thread