Fixing NSSegmentedControl Display Bug
Fixing NSSegmentedControl Display Bug
- Subject: Fixing NSSegmentedControl Display Bug
- From: Benjamin Einstein <email@hidden>
- Date: Thu, 28 Dec 2006 12:09:39 -0500
Hi All:
As you may know, there's a display bug with NSSegmentedControl when
using NSTexturedBackgroundWindowMask window style and size Regular
for the control. Like most mac developers, the 1 or 2 missing pixels
from the top of the control really gets to me and I HAVE to fix this
problem. Luckily, I found a post of someone using a brilliant little
trick to override a private method that fixes the display bug:
#import <Cocoa/Cocoa.h>
#define NormalSegmentedCellStyle 1
#define FlatSegmentedCellStyle 2
@interface FixedSegmentedControl : NSSegmentedControl {
}
@end
@interface NSSegmentedCell ( PrivateMethod )
- (void)_setSegmentedCellStyle:(int)style;
@end
@implementation FixedSegmentedControl
- (void)awakeFromNib
{
[self setFrameSize:NSMakeSize([self frame].size.width, 25)];
}
- (NSCell *)cell
{
NSSegmentedCell *cell = [super cell];
[cell _setSegmentedCellStyle:FlatSegmentedCellStyle];
return cell;
}
@end
This works beautifully when run in any app I have that uses my custom
window backing (which takes advantage of
NSTexturedBackgroundWindowMask), however, I get the following when
used in a preference pane:
[Session started at 2006-12-28 12:06:12 -0500.]
2006-12-28 12:06:15.708 MyApp[873] *** -[FixedSegmentedControl
initWithBundle:]: selector not recognized [self = 0x3c5790]
2006-12-28 12:06:15.713 MyApp[873] Exception raised during posting of
notification. Ignored. exception: *** -[FixedSegmentedControl
initWithBundle:]: selector not recognized [self = 0x3c5790]
InitWithBundle gets called for the class of the prefpane not of the
control within it (as far as I know). I've spend about 6 hours on
this problem and can't figure it out!
I also get this very bizarre error when dragging my .h file into IB:
"Cannot define a category for unknown class NSSegmentedCell"
But the Custom class shows up and all appears normal.
Any help would be greatly appreciated!
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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