Re: Table views with different NSArrayControllers sharing the same data object...
Re: Table views with different NSArrayControllers sharing the same data object...
- Subject: Re: Table views with different NSArrayControllers sharing the same data object...
- From: Keith Blount <email@hidden>
- Date: Thu, 28 Feb 2008 02:46:41 -0800 (PST)
Many thanks for your reply. I have a model object and a view object - DataList and DataListView. DataList has a -content array. The DataListView has an array controller whose contentArray is bound to the DataList's content array. Given that it is the view that observes the model, I have implemented -insertObject:inContentAtIndex: and -removeObjectFromContentAtIndex: in the *view* object, and in these methods it sets itself up as an observer for newly added list objects. This works fine when there is only one data list view. But if there are two views that both use the same DataList object's -content array, this means that each view is *only* set up to observe items that *it* adds; it will not observe items added by the other view. So, the second view won't notice when the first view adds another item to their shared content array and therefore won't update until you, say, sort the table, and then it won't observe any changes made to that object, either.
If I move the -insertObject:inContentAtIndex: etc methods to the model object, though, then I can't add the view as an observer to the inserted objects as the model knows nothing of the views. Unless I need to implement these methods in both the view *and* the model, the view's implementation calling the model's version of these methods... Given that both the view and the model have a -content array (the view's -content array is just a retained pointer to the model's -content array), maybe this is what I need to do?
As I say, my aim here is to have the same content array used in two table views that update so that they are identical when either manipulates the underlying data, to account for the situation where the user may create a split view in my app with the same table list open in both panes.
Thanks again and all the best,
Keith
----- Original Message ----
From: Adam P Jenkins <email@hidden>
To: Keith Blount <email@hidden>
Cc: email@hidden
Sent: Thursday, February 28, 2008 2:27:06 AM
Subject: Re: Table views with different NSArrayControllers sharing the same data object...
If
the
content
array
is
itself
a
property
of
another
object,
and
the
object
containing
the
array
property
has
indexed
accessors
for
the
array
property,
then
observers
of
the
array
property
will
be
notified
of
objects
being
added,
removed
or
replaced
in
the
array
in
addition
to
the
whole
array
being
replaced.
So
for
example
if
you
had
a
Course
class
with
a
"students"
property,
and
you
wrote
indexed
accessors
for
the
students
property,
then
observers
of
a
Course
object's
students
property
would
be
notified
if
students
are
added
or
deleted.
So
you
could
setup
an
observer
to
add
observers
for
newly
added
student
objects.
See
here
for
more
info
on
indexed
accessors:
http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueCoding/Concepts/AccessorConventions.html
On
Feb
27,
2008,
at
7:34
PM,
Keith
Blount
wrote:
>
Hi,
>
>
>
>
>
I'm
in
the
process
of
putting
together
a
small
list
view
based
on
an
>
NSTableView.
It's
pretty
simple
-
just
a
table
of
data
using
an
>
NSArrayController,
with
a
data
object
that
provides
the
array.
>
However,
in
my
app
it
is
possible
that
the
view
may
appear
in
a
>
split
view
with
a
copy
of
itself
in
the
other
view
(if
the
user
has
>
split
the
view
and
selected
the
same
list
view
for
both
views).
This
>
means
that,
if
the
user
makes
edits
to
the
table
in
one
view,
it
>
should
automatically
be
updated
in
the
table
in
the
other
view.
>
>
>
>
>
What
is
the
best
way
of
setting
this
up?
What
I've
tried
so
far
is
>
less
than
perfect.
I
bind
both
views/table
controllers
to
the
same
>
underlying
data
object
(array).
My
-setContent:
method
in
my
view
>
object
sets
up
observers
on
all
the
objects
in
that
array.
Still,
>
when
-addObject:
gets
called
on
one
of
the
tableControllers,
this
>
adds
an
object
that
the
other
table
controller
(controlling
the
>
other
view)
doesn't
know
about...
Obviously,
when
-adObject
gets
>
called,
-setContents:
isn't
called
(because
the
controller's
content
>
array
isn't
actually
changed)
so
the
other
view
doesn't
get
updated.
>
>
>
>
>
Essentially,
I
want
my
two
table
views
to
act
much
as
two
text
views
>
would
that
share
the
same
underlying
text
storage.
If
anyone
could
>
give
me
advice
on
the
best
way
to
achieve
this,
I
would
be
very
>
grateful.
>
>
>
>
>
Many
thanks
and
all
the
best,
>
>
Keith
>
>
>
>
>
>
____________________________________________________________________________________
>
Looking
for
last
minute
shopping
deals?
>
Find
them
fast
with
Yahoo!
Search.
http://tools.search.yahoo.com/newsearch/category.php?category=shopping
>
_______________________________________________
>
>
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
____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
_______________________________________________
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