• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Proper use of controllers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proper use of controllers


  • Subject: Re: Proper use of controllers
  • From: mmalc Crawford <email@hidden>
  • Date: Mon, 2 Feb 2004 02:18:32 -0800

On Feb 1, 2004, at 9:53 PM, John A. Debay wrote:
I have a quick question on how the new controller/binding layer fits in with various objects' delegates.

Umm, that's not a quick question :-)

For example, in my application, I have a standard master/detail interface very similar to the example in Apple's documentation:
http://developer.apple.com/documentation/Cocoa/Conceptual/ CocoaBindings/Tasks/masterdetail.html
I have all of the user interface elements bound correctly to the model through the controller layer, but am having trouble deciding where to place certain functionality. For example, when the user is entering data for a new table element into the detail view of my interface, there are two or three fields that are required, so if the user tries to save their changes with one of these fields blank, I need to throw up an alert box and prevent the changes from being committed to the model.

The easiest approach to take immediately would be, where you have suitable (textual) input, to flag the text field's validate immediately flag. Then implement suitable validation methods in your model class. For a simple example (albeit one which uses manual bindings) see <http://homepage.mac.com/mmalc/CocoaExamples/controllers.html> under Manual Bindings->Binding Options (<http://homepage.mac.com/mmalc/CocoaExamples/ManualBindings.zip>).

My first shot at this was to subclass the NSArrayController and override methods like commitEditing or discardEditing. The problem is that all of the controller methods are called frequently, and it is hard to tell that a certain behavior is taking place simply because one of these functions has been called.
Does this mean that I should be taking the traditional route of placing this functionality in my window controller class, and only if the data has been entered correctly by the user programmatically call the NSArrayController's insert: method? More broadly, are people just using the controller layer to automatically insert and display data, while still employing custom window controllers to hold most of the UI validation logic? Or are people moving most or all of this type of logic into various NSController subclasses?

I don't think there's a straightforward answer to this question. It depends in part on what your user interface / workflow is.

What I might suggest in the case here, though, is that the NSArrayController serve as the table view delegate. It's managing that aspect of the view, and so should be responsible for what happens there. If the detail view reflects the selection made in the table view, then you could disallow change in selection if the values in the currently-selected object are invalid...

For another example of an NSArrayController serving as a table view's delegate, see <http://homepage.mac.com/mmalc/CocoaExamples/ TableViewDnDController2.zip>; for a somewhat more complex arrangement of controllers, see < http://homepage.mac.com/mmalc/CocoaExamples/Weapons2.zip>.

mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Proper use of controllers (From: "John A. Debay" <email@hidden>)

  • Prev by Date: Re: Hyphenation?
  • Next by Date: Troubles with NSView...
  • Previous by thread: Proper use of controllers
  • Next by thread: MEETING: Chicago - Tuesday Feb 3rd 6:00 PM
  • Index(es):
    • Date
    • Thread