Software Definition of NSSegmentedCell

I am a little puzzled by how to instruct the programmatically created to NSSegmentedControluse an instance of the subclass NSSegmentedCell.

If I want to use subclasses NSSegmentedCellon NSSegmentedControlbuilt using IB, it will be as simple as doing the following:

  • Drag NSSegmentedControltoNSView
  • Switch to NSSegmentedCell
  • In the inspector, assign the class definition to a subclass (e.g., myCustomCell)

The task is completed.

However, when programmatically creating NSSegmentedControl, as in the following simplified example, I do not see how the cell subclasses ...

-(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:)];
}

NSSegmentedControlIt does not seem to have a method for defining a class for using cell instances in it.

As usual, any help is appreciated.

Update

[mySegmentControl setCellClass:[myCustomCell class], . , , , , AppKit.: - (

, ... -...

+3
1

, cellClass?

+ (Class)cellClass
{
    return [YourCustomCellClass class];
}
0

Source: https://habr.com/ru/post/1758112/


All Articles