14 Replies
      Latest reply on Jan 10, 2016 5:42 PM by Scenario
      indigo_jay Level 1 Level 1 (0 points)

        I'm not seeing how to get an event sent to my controller when a segmented control button is clicked. The Primary Action Triggered and Value Changed events in IB fire whenever focus changes between the segments. What I need is an event that's fired when one of the segments is clicked. Anyone figured out how to make that work?

        • Re: tvOS UISegmentedControl events
          mwhuss Apple Staff Apple Staff (625 points)

          When a segment becomes focused it fires the selection event and is intended to be the selection.

            • Re: tvOS UISegmentedControl events
              indigo_jay Level 1 Level 1 (0 points)

              Well, that makes the control significantly less useful. What if you need a control that allows multiple button presses - for instance incrementing or decrementing something? If you could get an event when the button was actually clicked (like UIButton) then the problem would be solved. I suppose using multiple UIButtons rather than separate segments is the only answer.

                • Re: tvOS UISegmentedControl events
                  robz Level 1 Level 1 (10 points)

                  You can respond to another event like a tap gesture using a tap gesture recognizer then check the value of your top control at that time.


                  I use:


                          myTopValue = myTopControl.selectedSegmentIndex;


                  then check the top value in a switch statement in my tap gesture recognizer like this:


                          switch (myTopValue) { ...

                • Re: tvOS UISegmentedControl events
                  indigo_jay Level 1 Level 1 (0 points)

                  How do you keep a user from accidentally changing the selected segment when focus enters/leaves the segmented control?

                  • Re: tvOS UISegmentedControl events
                    junkpile Level 6 Level 6 (2,485 points)

                    So you can't have a segmented control next to any other focusable element horizontally? Trying to move the focus away from the segmented control would change the selected segment.

                    • Re: tvOS UISegmentedControl events
                      Scenario Level 1 Level 1 (0 points)

                      If this is by design then that's a horrible UX. Selection should absolutely require a click. It's bad enough that users spazz out with the clumsy new TV remote, tying to keep their swipes predictable.


                      Case in point, here are two UISegmentedControls side-by-side:


                               [ Option 1 | Option 2 ]                                   [ Option A | Option B | Option C ]


                      We start with Option 1 selected. The user cannot move focus across the top without unintentionally selecting Option 2.


                      So UISegmentedControl is broken.

                        • Re: tvOS UISegmentedControl events
                          Scenario Level 1 Level 1 (0 points)

                          What's worse is that if you have (perhaps more important) buttons below that row of two UISegmentedControls, a swipe down does NOT move the focus to the lower controls. I can only swipe right, all the way across the UISegmentedControls (selecting each segment unintentionally) before the focus ever moves to the bottom of the view. Maybe this is because in my UI, the only other enabled button is in the bottom-right corner while the focus is in the top-left corner. In any case, segmented controls and a down-swipe should do what you expect them to do. This is terrible, Apple!

                      • Re: tvOS UISegmentedControl events
                        staticdreams Level 1 Level 1 (0 points)

                        Is there any update on this matter?

                        It drives me crazy that switch changes on focus. I want to be able control the state on button press. At this point segmented button press action is useless since everything is done in focus anyway.


                        Apple, please change this! Make it at lease possible to make selection by tapping the remote and not having it select control for in by just focusing.

                          • Re: tvOS UISegmentedControl events
                            YonatanBetzer Level 1 Level 1 (0 points)

                            Just use a UITapGestureRecognizer on the UISegmentedControl


                            assuming keyboardSegmentedControl is the segmented control, start by adding the gesture recognizer:


                            UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self


                            [self.keyboardSegmentedControl addGestureRecognizer:tapRecognizer];



                            handle the tap using a method like:




                                NSInteger selectedSegmentIndex = self.keyboardSegmentedControl.selectedSegmentIndex;

                                 // ... Just do what you want to do when the user clicks a segment.