Binding to an NSArrayController however binding is 1-way only.
Binding to an NSArrayController however binding is 1-way only.
- Subject: Binding to an NSArrayController however binding is 1-way only.
- From: dreamcat7 <email@hidden>
- Date: Wed, 17 Sep 2008 16:25:56 +0100
Hello,
I am stuck finding a solution for my array of arrays problem. - A
problem with a twist !
For the data must be displayed in an NSTableView and therefore it must
be structured in a particular way.
Mutable array of [items] with keypaths in each item making up the
columns of each row.
NSArrayController --[Points to]----> NSMutableArray* items [of
type Item] (*master array)
Each Item ------>: {
NSDate* date,
NSString* email,
float,
NSMutableData,
(id)context,
etc...
}
Whole thing (apart from the tableview itself) Is housed within a
library class. That is to say a framework.
I cannot expose my Items class to the outside world: it will almost
certainly have one or more hidden fields, the array of item is just
too unweildy and complicated to be used in the constructor function
for my class. At this point i would like to re0think my data design
however the real constraint is the NSTableView class because its just
so damn finnicky! NSTableView will only accept the one same
NSArrayController for all of its columns.
So for my constructor function i bind flat representations to (some
of) the keys. Each column becomes its own NSMutableArray.
NSMutableArray* dates;
NSMutableArray* emails;
etc...
[self bind:@"dates" toObject:itemsController
withKeyPath:@"arrangedObjects.date" options:nil];
[self bind:@"emails" toObject:itemsController
withKeyPath:@"arrangedObjects.email" options:nil];
This means i can for a pretty standard array of objects (dates emails
contexts, etc.) the client using my class can provide easily the data
needed into the constructor function. What could be simpler than an
array of NSString ?
I understand that wich Core Data maybe the problem can be overcome by
specifying relationships (and more easily model differen view of the
data). However i cannot use Core Data because its for a library class
which must be packaged in a framework. Am i mistaken about this - core
data being unsuitable for use in a framework ?
Looking at where i am stuck now, its with binding to my
arraycontroller at the keypath "arrangedObjects.date" and
"arrangedObjects.email". These rather special binding seems to be only
1-way. If i put data into the items array (the master array) it will
appear in the dates. If i put data in the array of NSDate* dates or
NSString* emails then the array controller cannot do anything. There
may not be an items yet existing at that index !
Continuing along my current road looks pretty rocky. Without the extra
help i need from the arrayController.
This is how i am currently going about it:
I observe the whole dates array, the emails array, and detect whenever
they change. If the original data in the master items array is not the
same (as the new dates array, or emails array).... I have to check it
wasnt simply because of the 1-ways binding, (and if not then find
which date or email was added / removed / changed ). Then must
propagate the change back to the master array the missing data. I got
that all working however when the arrays are sorted then its really a
mess to figure out which object was what, and you can imagine that any
of the array can be sorted at any time... Easily an endless loop of
changing, observing , and so it would be really great to get out of
that way of doing things.
Is there a more straightforward method for representing such data and
to update with binding a sorted NSArrayController ?
( still remaining as a framework implementation and compatible with
nstableview ?? )
Any help really appreciated thank you !
_______________________________________________
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