• 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: KVC Problems with Indexed Accessor - (A Solution)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVC Problems with Indexed Accessor - (A Solution)


  • Subject: Re: KVC Problems with Indexed Accessor - (A Solution)
  • From: joe OneNinetyTwo <email@hidden>
  • Date: Sun, 15 Oct 2006 15:41:33 -0700 (PDT)

I have a simple solution, and posted an example at...

http://www.chemistry.ohio-state.edu/~grandinetti/KVC.zip

The code gives a simple example to demonstrate how to
use Key Value Coding and implement Indexed Accessors
for a To-Many Property to display mutable data in a
NSTableView using an NSArrayController and bindings,
when the To-Many Property is packed into an NSData
object.

Hopefully, the code is self-explanatory.   In this
approach a simple object class (Datum) is created to
hold the table row values and an index.

Inside my NSDocument subclass are the methods ...

- (unsigned int) countOfData
- (Datum *) objectInDataAtIndex:(unsigned int) index
- (void) insertObject: (Datum *) datum
inDataAtIndex:(unsigned int) index
- (void) removeObjectFromDataAtIndex: (unsigned
int)index

which interact with the NSArrayController, through the
bindings with myDocument, to act like a property
called "data", which is indistinguishable from an
mutable array.

The trick here, is to use the Notification Center and
have the Datum object post a notification when its
value has changed (i.e., when the user edits a cell in
the tableView).  The NSDocument instance is registered
as an observer of the Datum notification, which calls
its method handleDatumChange: to update the NSData
object
when one of its packed values needs to be updated.

That's it.   Thanks to Scott Stevenson for encouraging
me to find a simple solution using bindings.

If anyone can see another solution that might be
simpler, please let me know.

Philip

--- Scott Stevenson <email@hidden> wrote:
> Do whatever works best, but I really think it's
> something to fix on
> the model side. As far as I can tell, Bindings
> already works fine for
> what you want to do.
>
>     - Scott

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: KVC Problems with Indexed Accessor - (A Solution)
      • From: Scott Stevenson <email@hidden>
References: 
 >Re: KVC Problems with Indexed Accessor for To-Many Properties (From: Scott Stevenson <email@hidden>)

  • Prev by Date: Re: Re: Where to find free EULA Templates?
  • Next by Date: WebView keyboard events
  • Previous by thread: Re: KVC Problems with Indexed Accessor for To-Many Properties
  • Next by thread: Re: KVC Problems with Indexed Accessor - (A Solution)
  • Index(es):
    • Date
    • Thread