• 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: Containers in Cocoa, adding objects to NSView programmatically?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Containers in Cocoa, adding objects to NSView programmatically?


  • Subject: Re: Containers in Cocoa, adding objects to NSView programmatically?
  • From: "I. Savant" <email@hidden>
  • Date: Sun, 27 Jul 2008 20:02:19 -0400

I'm been reading the documentation quit a bit but haven't found the answer.
My problem is that I don't really understand how containers work in Cocoa,
I know NSView, but how do I add an object to it programmatically, say a NSImage?

The term "container" is usually used to reference things like arrays and dictionaries (NSArray / NSMutableArray and NSDictionary / NSMutableDictionary, respectively).


The view hierarchy is a different animal. What have you searched the documentation for? The appropriately-named "Views Programming Guide for Cocoa" (referenced from the top of the NSView API reference) has a page even more appropriately-named, "Working with the View Hierarchy":

http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaViewsGuide/WorkingWithAViewHierarchy/chapter_5_section_1.html

The very first page of that section points to a subsection titled (most appropriately of all), "Adding and Removing Views from a Hierarchy ".

Now as far as an NSImage goes, you don't "add" images to views. NSImage is a model-layer object (search the Cocoa documentation for "MVC" or "Model View Controller"). You typically represent things graphically with a view. Therefore, NSImageView (a subclass of NSView, look it up in the documentation for usage details) accepts an NSImage instance. You can give the image view an image and add the image view to whatever parent view you wish -- adding an image view to another view is not the same thing as specifying the image that the image view displays.

--
I.S.


_______________________________________________

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


References: 
 >Containers in Cocoa, adding objects to NSView programmatically? (From: Jacob Ole Juul Kolding <email@hidden>)

  • Prev by Date: NSPopupButton and bindings to NSArrayController
  • Next by Date: IB not recognizing class hierarchy
  • Previous by thread: Containers in Cocoa, adding objects to NSView programmatically?
  • Next by thread: NSPopupButton and bindings to NSArrayController
  • Index(es):
    • Date
    • Thread