• 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: Categories, Protocols, Delegates and ToolTips
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Categories, Protocols, Delegates and ToolTips


  • Subject: Re: Categories, Protocols, Delegates and ToolTips
  • From: Marco Scheurer <email@hidden>
  • Date: Wed, 19 Jun 2002 16:39:42 +0200

On Wednesday, June 19, 2002, at 03:06 pm, Paul Cezanne wrote:

Tooltips?

That is where is all started. I need a form of roll over help. Tooltips aren't good enough (user testing has spoken, the objection was primarily how they faded away after a set time). I want to place the mouse over a control and have help text appear in a help text area.

Let's assume that this is a good idea...

First problem I see with Categories is that from my reading they are meant to add methods to an existing class. The methods I need, resetCursorRects, mouseEntered and mouseExited, are already existing methods. So I don't need to make a category for them but I do need to make an implementation for them, but where do I put them? Right now they are in a subclass of NSButton which works great for buttons but not at all for other controls.

If you implement in a category methods that already exist, your implementation will replace the original, which could be risky.

If I make a subclass of NSControl than I can't assign the connections in Interface Builder, a button needs a datatype that is a descendant of NSButton, not NSControl.

I do not understand what you mean.

Protocols seem to have the same problem in this application. First, I don't need them because the methods are already there (and probably part of some protocol anyway) and secondly, I don't know how to hook them up without subclass every type of control that I use, which I want to avoid.

Protocols are declarations, they will not help.

Delegates seem like they could help a lot, but NSViews don't have delegates, there is nothing in IB to control drag to.

http://cocoa.mamasam.com/COCOADEV/2002/01/1/21131.php was very helpful but none of the alternatives seem to work for me.

And of course the final problem is that even if I could get Categories to work, a category can only have methods, I can't add an new IBOutlet so the control knows where to draw its new help text. With my subclasses NSButton this was really easy.

What I would try is a form of delegation:

(1) Subclass NSControl and either send an NSNotification or send an action to nil (it would then be caught by the first responder that can respond). For instance:

- (void) mouseEntered:(NSEvent *) theEvent
{
[super mouseEntered:theEvent];
if (([self toolTip] != nil) && (![[self toolTip] isEqualToString:@""]) {
[NSApp sendAction:@selector(mouseEnteredAction:) to:nil from:self];
}
}

(2) Implement the action mouseEnteredAction: in your window's delegate. This object can have an outlet to the help text area, and can query back the sender for details:

- (void) mouseEnteredAction:(id) sender
{
// assumes [sender toolTip] != nil, maybe an assertion would be nice.
[helpTextArea setStringValue:[sender toolTip]];
}


(3) Use poseAs: to replace NSControl with your subclass. poseAs: as the same ivar limitation as categories (you cannot add instance variables), but at you've got access to super's implementation. And you can do without ivar in that case.


Marco Scheurer
Sen:te, Lausanne, Switzerland http://www.sente.ch
_______________________________________________
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: Categories, Protocols, Delegates and ToolTips
      • From: Paul Cezanne <email@hidden>
References: 
 >Categories, Protocols, Delegates and ToolTips (From: Paul Cezanne <email@hidden>)

  • Prev by Date: Re: Categories, Protocols, Delegates and ToolTips
  • Next by Date: Snapping Window Locations (partial solution)
  • Previous by thread: Re: Categories, Protocols, Delegates and ToolTips
  • Next by thread: Re: Categories, Protocols, Delegates and ToolTips
  • Index(es):
    • Date
    • Thread