TVOS : Swift : move focus programmaticlly

This should be a no brainer function.
I have a UIView with 52 focusable subviews (think playing cards)
The card with the focus has an Arrow superimposed over it… the coordiantes of the arrow are adjusted as various cards get/lose focus. When a card has the arrow, and it is then selected, it is removed from the screen, This leaves the arrow in Limbo. What I need to do is find the card nearest the current arrow location (that part was easy), and then move the focus to THAT card.

This is the part that should be easy-peasy, but seems to be near impossible .

I have tried literally dozens of solutions proposed by articles on the net, most all of them seem to work (at least the log says so), but the focus never seems to go where I want.

Anyone have an idea??? The tvOS Focus Engine is a PITA to say the least

how about nextResponder? Does that exist on tvOS?

This may not help, but in SwiftUI you add a focus tag to views. .focused( $focusedField, equals: item.id ) and to set focus to a control, you simply set the property focusedField = item.id.

1 Like

yes it has NextResponder… no that did not work…

remember… FOCUS on tvOS is not quite the same as Focus in iOS or even Xojo. Since tvOS has no mouse or keyboard, you need to move the “Focus” from one object to the next in order to select it.

In most tvOS apps, this focus is denoted by the object growing a bit bigger… instead I opted to super impose an Arrow and leave the object size alone

So you have 52 objects rendered, and one of them is ‘blessed’
When the blessed one is removed, surely all you need to do is pick another , ‘bless’ it, and invalidate the display?
A boolean property of the object would do that, regardless of whether or not TVOS actually has a ‘display item with the focus’
Why does it need to be focus, if there is no keyboard?

I never gave it any thought as I never considered making an app for a TV. I’d have to use Flutter as we don’t have a modern TV, our TV runs GoogleTV, but I’ve not really bothered to download any apps for it.

your first statement is correct. but in tvOS in order to be “blessed” as you call it, it must have the focus. No events can be accounted for on a object that is not the focused item.

As I said, the navigation paradighm is no where close to the of iOS or macOS

Finally got one method I found on the net to work… but I had to re-engineer how I was dealing with the focus engine …