I spent the last couple of weeks adding tvOS support for the widget that I packaged with my SVG SVGgh rendering library, so I have some sense for that. The problem is that I think this is a new or new kind of action: UIControlEventPrimaryActionTriggered, which is dispatched when the control wants to report commitment to the action, as in this response to the completion of the UIPress in my GHButton . Remember to connect the selector to this new action in your storyboard.
-(void) pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event { [self sendActionsForControlEvents:UIControlEventPrimaryActionTriggered]; self.beingPressed = NO; self.selected = self.selected; }
But in the segmented control analogue, the action is not set when the button is pressed, but when the focused segment changes, as in the following (heavily edited for clarity) code from my GHSegmentedControl class:
- (BOOL)shouldUpdateFocusInContext:(UIFocusUpdateContext *)context { BOOL result = NO; if(context.nextFocusedView == self) { result = YES; [self highlight:YES]; if(context.focusHeading == UIFocusHeadingRight) { [self incrementValue]; [self.parentContent.control setNeedsFocusUpdate]; [self sendActionsForControlEvents:UIControlEventValueChanged]; } else if(context.focusHeading == UIFocusHeadingLeft) { [self decrementValue]; [self.parentContent.control setNeedsFocusUpdate]; [self sendActionsForControlEvents:UIControlEventValueChanged]; } } return result; }
Now that I am thinking about this, perhaps I should also send the UIControlEventPrimaryActionTriggered action to the segmented control, but UIControlEventValueChanged seems to work as I expect.
source share