views:

26

answers:

0

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:

  1. Drag an NSSegmentedControl into the NSView
  2. Click through to the NSSegmentedCell
  3. In the inspector assign the class definition to the subclass (e.g. 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...