tvOS UISegmentedControl events

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?

Replies

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

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.

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

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.

There's a small delay between selection, so if a user moves focus quickly across the segments there will be no selection change.

I think what people might expect is more like the way it works in the text entry screen. ABC / abc / #+- are not automatically selected on focus change; only on click. That is the very first experience users will have with the Apple TV (setting up iCloud etc.) so that would set users' expectations. It seems odd that the "standard" control available to apps doesn't work the same way.

I wholeheartedly agree. The current behavior is pretty useless.

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.

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

action:@selector(tap:)];

[self.keyboardSegmentedControl addGestureRecognizer:tapRecognizer];



handle the tap using a method like:


-(void)tap:(UITapGestureRecognizer*)gestureRecognizer

{

NSInteger selectedSegmentIndex = self.keyboardSegmentedControl.selectedSegmentIndex;

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

}

If you hide the uisegmentedcontrol then it will not receive any events.


In objective-C, I do:


[myTopControl setHidden:YES];


and then the control doens't change values.

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) { ...

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.

How would that help, when the control is updating its visuals as if a selection occured without a click?

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!