Reputation: 3798
I am a little stumped as to how to instruct a programmatically created NSSegmentedControl
to use a subclass instance of an NSSegmentedCell
.
If I want to use a subclasses NSSegmentedCell
on an NSSegmentedControl
built using IB it would be as simple as doing the following:
NSSegmentedControl
into the NSView
NSSegmentedCell
myCustomCell
)Job done.
However, when programmatically creating an NSSegmentedControl
as in the following simplified example, I don't see how to subclass the cell...
-(void)creatSegmentControl {
if (!mySegmentControl)
mySegmentControl = [[NSSegmentedControl alloc]
initWithFrame:NSMakeRect(0,0 400,20)];
[mySegmentControl setSegmentCount:2];
[mySegmentControl setLabel:@"First" forSegment:0];
[mySegmentControl setLabel:@"Second" forSegment:0];
[mySegmentControl setTarget:self];
[mySegmentControl setAction:@selector(segmentClicked:)];
}
NSSegmentedControl
does not appear to have a method for defining the class to use for it's segment cell instances.
As usual, any and all help appreciated.
Update
Tried implementing [mySegmentControl setCellClass:[myCustomCell class]
but that didn't work either. I was thinking that maybe it inherited the ability to set it's cell class like other AppKit controls. :-(
This must be possible though... somehow...
Upvotes: 3
Views: 2429
Reputation: 1026
The property cellClass
is in the deprecated category.
You need to make an instance of your custom class and set NSControl
's cell property, before anything else (yes NSSegmentedControl
inherits from NSControl
)
NSSegmentedControl* oSegment = [[NSSegmentedControl alloc] init];
QPDFSegmentedCell* csell = [[QPDFSegmentedCell alloc] init];
oSegment.cell = csell;
Upvotes: 0
Reputation: 639
Kinda late, but wouldn't overwrite cellClass work?
+ (Class)cellClass
{
return [YourCustomCellClass class];
}
Upvotes: 0