MVC and cocoa best practice bindings

Suppose I have a view, myView, a view controller, myViewController, and some kind of model myModel object. Next, let's say the model has two properties compatible with KVO, arrayOfPeopleNamesand arrayOfAnimalKinds(both NSStrings).

In my opinion, I want to have two pop-ups associated with the contents of these two arrays.

My question is, if myController has a link to myModel and the dropdown is tied to myViewController, is it good practice to set the path for keys along the lines myModel.arrayOfPeopleNames?

Or do I need to configure an additional NSArray in myViewController that displays the object in myModel and binds to this key link?

The first seems a lot simpler in terms of implementation (I don't need the controller array to display the model array), but I'm wondering if it demonstrates the model for presentation.

opinions?

+5
source share
1 answer

You should not reflect the model array in the controller. Although I would not be too worried about binding directly to the model array in a very simple case, you can also bind your user interface objects to the NSArrayController, which controls the model array. This will provide a separation between the model and the user interface and, more importantly, it will perform tasks such as sorting, selecting, adding and deleting objects, etc.

, , KVO, "" , , . , KVO , ( IB). , , , .

, , , " " . , , . .

, , , . , , Cocoa, .

+8

All Articles