Re: what do I need the NSArrayController for?
Re: what do I need the NSArrayController for?
- Subject: Re: what do I need the NSArrayController for?
- From: Roland King <email@hidden>
- Date: Wed, 02 Apr 2014 21:54:32 +0800
... ignore .. sent to Cocoa where I intended to post it in the first place ..
On 2 Apr, 2014, at 9:52 pm, Roland King <email@hidden> wrote:
> I'm not great with bindings, but I'm trying to learn.
>
> I have an array property in my model which is a list of serial devices, I want to display it in a table view and let the user select one. So I instantiated a tableView, an NSArrayController, bound the contents of the NSArraycontroller to the serialDevices property and added a few other bindings to the Table View and Table View Column; OK now I have a list of devices on the screen.
>
> In the model I had a selectedSerialDevice property, which was the selected object out of the serial device array, I wanted to bind that to the selection on the table view. I could find only a Selection Indexes binding on a Table View so I changed the model to have an NSIndexSet with one index representing the selected serial device, which I bound through the NSArrayController and then to the table view. So already my model isn't actually what I wanted, I wanted a selected object, but the NSArrayController and table View want an index set so now my model has an index set in it to make the other objects happy. The view/viewcontroller is driving the model .. hmm.
>
> At this point I realized the NSArrayController was doing nothing. It was forwarding my array of objects and my selected index set I didn't want to the Table View. I took it out and bound direct to the equivalent properties on the model, everything continued to work. My array shows, I select an object and the index set I didn't want is updated in the model.
>
> So that led to two questions
>
> 1) What is the point of the NSArrayController? It mirrors the bindings on the Table View so it really seems to do nothing. If it were smart and converted a model property like .. selected object into the index set the table view wants, that would be useful, that would be what I'd usually use a Controller for, to turn model-speak into view-speak, but it doesn't, it just passes through.
>
> 2) Do I really have to change my model to present an index set for 'selection' because there is no standard controller object which can turn objects/selected object into something a table view can use?
>
> I thought bindings were supposed to remove the need to write glue code to match a model to a view, they do .. if the model matches the view .. in which case the NS*Controller objects don't actually do much.
>
> What did I miss?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden