• 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: Subclassing NSControl
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Subclassing NSControl


  • Subject: Re: Subclassing NSControl
  • From: Scott Anguish <email@hidden>
  • Date: Wed, 14 May 2003 04:14:10 -0400

On Wednesday, May 14, 2003, at 03:51 AM, Lorenzo wrote:

Hi,
I have two own subclasses:
MYTextField subclass of NSTextField
MYImageView subclass of NSImageView

For many of their behaviours these 2 classes work the same way,
e.g. they respond to the mouse clicks the same way,
if the user clicks holding down the Control key, a pop-up menu appears...

So I thought to group these 2 subclasses under a superClass "MYBox",
and to describe the common behaviours (like mouseDown, mouseUp)
in this new superClass "MYBox".


You can't really do that. NSTextField and NSImageView both inherit from NSControl.

what you could do is have your own subclasses of NSTextField and NSImageView and then have the mouseDown: and mouseUp: methods in your subclasses call a procedure (yep, an old fashion procedure) passing the sender and it's parameters

void CommonMouseDownHandler(NSEvent *theEvent, NSControl *sender)
void CommonMouseUpHandler(NSEvent *theEvent, NSControl *sender)

this would let you put all the code in a single shared location, and still give you all the objective-C goodness of calling the objects..

You could even use class methods and make it into a class if you wanted to (but I don't see the advantage in this case... maybe if you had a single set of shared data that they needed to access a singleton might make sense)
_______________________________________________
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.
  • Follow-Ups:
    • Re: Subclassing NSControl
      • From: David Remahl <email@hidden>
References: 
 >Subclassing NSControl (From: Lorenzo <email@hidden>)

  • Prev by Date: Subclassing NSControl
  • Next by Date: Re: Subclassing NSControl
  • Previous by thread: Subclassing NSControl
  • Next by thread: Re: Subclassing NSControl
  • Index(es):
    • Date
    • Thread