Show NSSegmentedControl menu when segment clicked, despite having set action

后端 未结 4 1512
清酒与你
清酒与你 2021-01-02 12:39

I have an NSSegmentedControl on my UI with 4 buttons. The control is connected to a method that will call different methods depending on which segment is clicked:



        
4条回答
  •  梦毁少年i
    2021-01-02 13:07

    This is the Swift version of the answer by J Hoover and the mod by Adam Treble. The override was not as intuitive as I thought it would be, so this will hopefully help someone else.

    override var action : Selector {
            get {
                if self.menuForSegment(self.selectedSegment) != nil {
                    return nil
                }
                return super.action
            }
            set {
                super.action = newValue
            }
        }
    

提交回复
热议问题