• 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: Adding a new row to NSTableView dynamically using bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding a new row to NSTableView dynamically using bindings


  • Subject: Re: Adding a new row to NSTableView dynamically using bindings
  • From: Chris Hanson <email@hidden>
  • Date: Sun, 22 Jul 2007 13:47:31 -0700

On Jul 22, 2007, at 8:14 AM, vibhatha v wrote:

I am trying to add a new row to an NSTableview dynamically through code.

Please let me know where i have gone wrong.
I need to add a new entry to my entity set too whenever a new row is added
to the tableview.

You're thinking about this all wrong.

You should be thinking about adding a new object to whatever collection is being presented by the table view. You should *never* think in terms of "add a new row to a table view;" while some platforms may encourage that sort of thing, it's completely backwards within the Model-View-Controller architecture that Cocoa is built around.

If you're using bindings, as long as you add your new model object to the collection that is being presented by your table view in a KVC/KVO- compliant fashion[1], the table view will automatically be updated to show it. No extra work required on your part.

  -- Chris

[1] Being *certain* to manipulate the collection in a KVC/KVO- compliant fashion is where a lot of people fall down. For a view that's bound via an NSArrayController to a key representing a collection of model objects, you *cannot* just manipulate the underlying collection and expect things to work. Instead, you must either use the appropriate mutation methods for the *key* that is bound to, or you must use the mutable *proxy* for the key that is bound to as returned by the method -mutable{Array,Set}ValueForKey:. Be sure to read and understand <Foundation/NSKeyValueCoding.h> and <Foundation/NSKeyValueObserving.h> in their entirety, as well as the appropriate Programming Guides.

_______________________________________________

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: 
 >Adding a new row to NSTableView dynamically using bindings (From: "vibhatha v" <email@hidden>)

  • Prev by Date: Re: fortran90 code
  • Next by Date: Re: beginSheet, doesn't stop NSThread
  • Previous by thread: Re: Adding a new row to NSTableView dynamically using bindings
  • Next by thread: fortran90 code
  • Index(es):
    • Date
    • Thread