Re: controller question
Re: controller question
- Subject: Re: controller question
- From: Ariel Feinerman <email@hidden>
- Date: Wed, 28 Sep 2011 19:58:36 +0300
I try to expline the problem. There is m_array (M) loaded from the file in
the one nib, then there is other two view controllers' nibs (C) with views
(V). One of them uses array controller to show and delete only, when the
other is used for insertion only throw dragging therefor no need in
controller.
2011/9/28 Quincey Morris <email@hidden>
> On Sep 27, 2011, at 17:51 , Ariel Feinerman wrote:
>
> So in the case of insertion to m_array, we just have to reset content
> property:
>
> // somewhere in the code
> [self willChangeValueForKey: @"content"];
> [m_array insertObject: url atIndex: 0];
> [self didChangeValueForKey: @"content"];
>
> // in the -observeValue...
>
> [controller setContent: m_array];
>
> well?
>
>
> No, that's not it. I'm sorry I've confused the issue for you by saying
> something wrong earlier.
>
> Let's reset and start again.
>
> 1. You have an array (m_array) which you create and maybe populate in
> advance. This is the M in MVC.
>
> 2. You have an array controller (controller) which you create or maybe
> instantiate in a nib file. This is the C in MVC.
>
> 3. You have a view, for example a table view whose columns are bound to the
> array controller. This is the V in MVC.
>
> With this one-time line of code:
>
> [controller setContent: m_array];
>
> you tell the array controller to *manage* m_array for you. There's no copy
> "inside" the array controller. That answers one of your questions.
>
> If you want to add or remove objects from m_array programmatically, then
> use the various [NSArrayController addObject…], [NSArrayController
> removeObject…], [NSArrayController insertObject…] methods. These method do
> two things: they *both* change the underlying array *and* tell the array
> controller that the underlying array changed. That answers another of your
> questions.
>
> So long as you use these methods, if you want to know what objects the
> array controller is managing, you can just look at m_array. That answers
> your last question.
>
> I understand these issues
In this setup, KVO doesn't enter the picture, and I was wrong to say it did.
>
> That's basically the whole story, but I'll add two footnotes:
>
> -- If you need KVO notifications to be sent because *other* objects in your
> app need to be notified when things change, you should not use an array
> *object* (m_array), but rather an array *property* of some other object
> (such as a "myArray" property of your app delegate). In that case, you would
> likely bind the array controller to this array property, instead of using
> setContent, and everything can then be done KVO-compliantly.
>
> -- If there's no view involved here, there's really no good reason to be
> using an array controller at all. I don't think you mentioned a view, so I'm
> not sure what to assume.
>
> Is that clear? I think I've said it right now.
>
>
> completely ;-)
_______________________________________________
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