• 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: NEWBIE: Connecting up all those Ms, Vs and Cs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NEWBIE: Connecting up all those Ms, Vs and Cs


  • Subject: Re: NEWBIE: Connecting up all those Ms, Vs and Cs
  • From: Damien Sorresso <email@hidden>
  • Date: Tue, 16 Aug 2005 09:46:38 -0500

On 13 Aug, 2005, at 2:00 PM, Stephen P Lesniewski wrote:
Quick summary of the problem, write a document-based Cocoa app that allows the user to draw ovals. Add Save/Load and Undo (if you're feeling ambitious =). I'm (perhaps) cheating a bit and combining by MC into a subclass of MyDocument. Up til this point examples/ exercises linkages were Target/Action and that clicks with me, but now I have an mouseUp event that needs to create an "oval" in the Model/Controller and that's not clicking. I thought I had it with an IBOutlet in a the StretchView (subclass of NSView) linked back to "My Document" in IB, but when I started to implement the Save functionality I found that object that MyDocument was saving was different than the one StretchView was drawing from.

How should the View be linking up with the Controller? In a perfect Cocoa App how would you setup linkages between M, V, and C?

This all goes back to laying out the application before you actually start writing it. Here's what I generally do.


First, create the model classes. Set them up so that every piece of data an outside class could ever need access to is available. If you're going to be working with arrays of these model objects, you'll want to create a management class containing an `NSArray' or `NSMutableArray' which you can perform manipulations on through the class' methods.

Secondly, if you need them, create your `NSView' subclasses. Limit the methods in these classes to explicit drawing commands. So if you've got a view that draws ovals, only put methods relevant to that drawing, like say, `drawNewOvalWithRadius1:AndRadius2:' or things like that. You should not link any `IBAction's or `IBOutlet's to your view subclasses. That's what you have controllers for.

Then set up your controllers. For view controllers, you'll have to use your best judgement as to when it's appropriate to use individual NIB files. Generally, though, if you're going to be loading and unloading subviews, you should use separate NIB's. And also, if your custom view is complex enough to warrant a controller object, you should probably put it in its own NIB file anyway. When making a view controller, ALWAYS include an `IBOutlet' to the view itself. Your controller should decide when the view needs updating, not the view itself. Check out the `NSBundle' documentation on using separate NIB files.

Hope this helps.
--
Damien Sorresso
Macintosh Developer
Computer Infrastructure Support Services
Illinois State University
email@hidden
309.438.5777

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >NEWBIE: Connecting up all those Ms, Vs and Cs (From: Stephen P Lesniewski <email@hidden>)

  • Prev by Date: Resizing an image and representing it in JPEG form
  • Next by Date: Subviews use superview's `drawRect' method?
  • Previous by thread: Re: NEWBIE: Connecting up all those Ms, Vs and Cs
  • Next by thread: Serial communication on MacOSX
  • Index(es):
    • Date
    • Thread