• 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: NSCell subclassing to contain other NSCells
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSCell subclassing to contain other NSCells


  • Subject: Re: NSCell subclassing to contain other NSCells
  • From: email@hidden
  • Date: Fri, 2 Dec 2005 11:52:48 -0800

email@hidden wrote:

I'm looking for an attack strategy on subclassing an NSCell.

Here's a simplified scenario of what I want to do. This scenario is only for the sake of discussion.

I have a list of books I allow people to borrow all the time. I want to list my books as NSCells within an NSMatrix. Within each cell I want to have a large thumbnail of the book cover, the title and author of the book and 2 controls under the title and author information. These controls are...
1. Button to allow me to set whether book is being borrowed or not
2. Text field to allow me to type the name of the person that has the book.

What I think I should do is create a subclass of NSCell (say BookCell) and use member variables for other NSCells (NSImageCell, NSTextCell, NSButtonCell, NSTextFieldCell) within it and control them all independently. But, I can't figure out how to have my NSCell treat these other cells similar to an NSView containing subviews. I was hoping for something similar to NSView's addSubview method to allow me to have subcells, but no such thing exists that I could find.

Any assistance would be appreciated.
You'll need to have some type of layout calculation and a list of cells.
You subclass NSCell then add the instance variables (an Array for the subcells).
You then decide the layout of these items and also layout relative to each-other (it gets tricky and potentially messy here).
Then in your master cell, you calculate layout and draw and call the other cells to draw as well.
Remember, NSCell does not retain its NSSize, its only notified at runtime, though this could be
added by a subclass or layout engine (something I'm investigating...)

If you wanna pipe events to each cell, then in the NSEvent response methods (like beginTracking:InView:)
you see if that mouse down hits any subcells, and then forward the NSEvent to that particular cell by calling its same method...

Its a bit of work, and I would suggest making a lightweight reusable behavior, it may take more time in the
beginning, but over time you'll save it (I should know, its not fun doing this over and over)

Good luck.


_______________________________________________
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
  • Prev by Date: NSDrawer FirstResponder problem
  • Next by Date: Re: Is Apple's singleton sample code correct?
  • Previous by thread: NSCell subclassing to contain other NSCells
  • Next by thread: Shift-key state without an event?
  • Index(es):
    • Date
    • Thread