1

I have a NSSegmentedControl in a toolbar. Its mode is set to "momentary" because the segments should appear to work like buttons, not like permanent selections.

The rules for enabling:

  • When content is selected, all 3 segments should be enabled.
  • When no content is selected, only the last one should be enabled.

So I cannot disable the whole control but only some segments.

let enabled = hasSelection()

AddDimensionSegmentedControl.contextualSegments // = (0...1)
    .forEach { (segment: Int) in
        self.setEnabled(enabled, forSegment: segment)
}

That works quite well so far:

disabling works

But I can still click on disabled segments and have them selected even though that's not the selection mode

enter image description here

What I tried:

  • when the selection changes, deselect the segment again
  • when the toolbar validates, set selectedSegment = -1

Still the disabled-looking selection stays in tact. Any ideas?

ctietze
  • 2,805
  • 25
  • 46

1 Answers1

0

Someone pointed out something in a chat, and here's the solution I found: you have to disable both the NSToolbarItem that represents the segment and the segment itself.

If you only have 1 NSToolbarItem that contains the NSSegmentedControl instead of a NSToolbarItemGroup, you maybe don't have to do that.

ctietze
  • 2,805
  • 25
  • 46