setToolTip: not working
setToolTip: not working
- Subject: setToolTip: not working
- From: Ben Haller <email@hidden>
- Date: Mon, 16 Nov 2009 12:11:49 -0500
I'm having difficulty setting tooltips on some views in code. This
should be a simple matter of calling setToolTip: on the views in
question, as far as I can tell from the docs, but that is not working
for me. I surfed the various lists for prior questions about this,
and found several, but didn't find any answers, so I thought maybe I'd
ask again. :->
I'm seeing this for both NSButtons and my own custom view. My
custom view is very simple, so I'll show you that:
@interface AKColorStripeView : NSView
{
float minValue, maxValue;
int discreteValueCount;
}
- (void)setMinValue:(float)minValue maxValue:(float)maxValue;
- (void)setDiscreteValueCount:(int)count;
@end
@implementation AKColorStripeView
- (void)geneticBasisChanged
{
if (discreteValueCount == 0)
[self setToolTip:[NSString stringWithFormat:@"Genetic values are
continuous, from %.1f to %.1f", minValue, maxValue]];
else
[self setToolTip:[NSString stringWithFormat:@"Genetic values are
discrete, with %d possible values from %.1f to %.1f",
discreteValueCount, minValue, maxValue]];
[self setNeedsDisplay:YES];
}
- (void)setMinValue:(float)newMinValue maxValue:(float)newMaxValue
{
minValue = newMinValue;
maxValue = newMaxValue;
[self geneticBasisChanged];
}
- (void)setDiscreteValueCount:(int)count
{
discreteValueCount = count; // defaults to zero, meaning continuous
genetic values
[self geneticBasisChanged];
}
- (void)drawRect:(NSRect)dirtyRect
{
... nothing surprising here ...
}
- (BOOL)isOpaque
{
return NO;
}
@end
A few things I've tried:
- ran it on 10.5.8 and 10.6.1, and the tooltip didn't show up on either
- tried moving the setToolTip call into -viewDidMoveToWindow, thinking
that maybe the tooltip setup didn't work properly before the view had
a window to live in, but that didn't help
- tried calling -removeAllToolTips on the view before calling
setToolTip:, but that made no difference
I'm at a complete loss. Is anybody else setting tooltips on simple
views (i.e. not on toolbar items, matrix cells, etc., where the code
path is different from the base -[NSView setToolTip:] code path)? If
so, is there any secret incantation that I'm missing here? As I
mentioned, I'm seeing the same problem with setting tooltips on
NSButtons that are created and added to a window in code; that's as
simple as a single-line call to -setToolTip: on the button with a
static NSString, so there's not really much code to post, but here's a
snippet:
playOneLifeStageButton = [[NSButton alloc]
initWithFrame:NSMakeRect(modelRowOrigin.x, modelRowOrigin.y + 6 - 1,
29, 30)];
[playOneLifeStageButton
configureForEnabledImageNamed:@"EndEnabled.tiff"
pressedImageNamed:@"EndPressed.tiff" toggles:NO];
[playOneLifeStageButton setToolTip:@"Step forward one phase"];
[playOneLifeStageButton setAction:@selector(playOneLifeStage:)];
[contentView addSubview:playOneLifeStageButton];
The tooltip doesn't show up for that button, either.
Thanks!
Ben Haller
Stick Software
_______________________________________________
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