Re: NSArrayController, managedObjects and KVO
Re: NSArrayController, managedObjects and KVO
- Subject: Re: NSArrayController, managedObjects and KVO
- From: Quincey Morris <email@hidden>
- Date: Tue, 25 Mar 2008 13:29:54 -0700
On Mar 25, 2008, at 12:04, Brian Krisler wrote:
I have an NSArrayController in a NIB that contains Core Data Entities.
The represented entity has a two values, a boolean and a name, and
these are displayed in a table as a checkbox and text. (two columns).
All I would like to do is get notified with the check box is
selected and
have a way of determining with item was selected.
In my UI controller, I created an IBOutlet for my NSArrayController,
then in IB, I created the binding. Then in my UI controller's
awakeFromNib, I add and observer to my array controller.
While this appears to somewhat work, my observer gets notified
whenever a
row in my table is selected, I can not figure out how to determine if
the checkbox value changed. Since selected the text in the table also
fires a selection observable.
I have tried different values for my keyPath: arrangedObjects,
selectedObjects, selection
and in every instance, I get the same results. If I expand the
keyPath
(i.e. selection.isSelected), I expected that to notify on the
selection of the isSelected boolean
field, however this is also not the case. I found I could put
anything in the keyPath
and get the same results. (selection.blah)
I found in the archive a thread indicating that for
NSArrayControllers, the source array,
not the managed object array should be watched. I have to admit, I
have been unsuccessful
in learning which binding is the source array, so I appear to be
missing something there.
At this point, I feel like I am just chasing my tail.
You're not entirely clear whether your ultimate goal is to find out
when the value of the boolean changes, or to find out which rows of
the table view are selected.
If you just want to know if the boolean changes, then the selection
doesn't matter and the array controller doesn't enter the picture --
you simply arrange to observe suitable objects in your core data
model. How you do this depends on the model. You might explicitly
observe that boolean property of every object that has it, or you
might observe a parent object's to-many relationship that represents
the collection of objects having the boolean property (and is also
what you're binding the array controller to, I assume).
Finding out which objects are selected is a bit different, because
this information is in the user interface (the table view), not in the
core data model. In that case, you can observe the array controller's
selection or selectedObjects as a way of finding out *when* the
selection changes. When that happens, if you need to know what core
data model objects are actually selected, selectedObjects is the
answer. Or if you need to know which table rows are selected, you can
use table view methods like selectedRow to query the information.
(I've always just assumed that table view properties are not
themselves KVC-compliant, and therefore not directly observable, but I
could easily be wrong about that. In that case, you could observe the
table view instead of the array controller. But I suspect you don't
really care about the selection anyway.)
_______________________________________________
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