Navigate Between Buttons Simulator not working

I'm having a hard time understanding how you navigate between buttons on the screen with the simulator.


I know you are supposed to hold down Option and then move the mouse on the Apple Remote Simulator, however I can not get focus to leave the first button in my UI.

Answered by Engineer in 70253022

There are a few things to try to help debug this:


1. What is the on-screen arrangement of your buttons? When the system decides to move focus, the area that's searched for candidates is a rectangle that extends out from the currently-focused view in the direction that you're moving. If that rectangle doesn't intersect with the button you're trying to move to, then that would explain why it's not working for you.


2. If the on-screen arrangement seems okay, you can pause your app in the debugger and ask the button you thought focus would move to why it isn't accepting focus by sending it the message "_whyIsThisViewNotFocusable"


3. If you can get a breakpoint to get hit within didUpdateFocusInContext:animationCoordinator: then you can use the Xcode QuickLook feature to see a visual representation of how the focus engine "sees" your UI.


For those last two, see the App Programming Guide (scroll to the bottom): https://developer.apple.com/library/prerelease/tvos/documentation/General/Conceptual/AppleTV_PG/WorkingwiththeAppleTVRemote.html

Did you get this to work? That really is all there is to it:


- Make sure Hardware > Show Apple TV Remote is on

- Hold [Option]

- Move/Hover (i.e., don't click) your mouse over the big empty black area of the little remote window.

Tried that. When the app first launches the first button is highlighted. I click on it with the simulator remote and the thread starts counting as it should. The button is in a selected state. I hold down [Option] and move the mouse on the small track pad of the simulator remote and nothing happnes. The selected button remains selected and "focus" does not leave it to the next botton.

Accepted Answer

There are a few things to try to help debug this:


1. What is the on-screen arrangement of your buttons? When the system decides to move focus, the area that's searched for candidates is a rectangle that extends out from the currently-focused view in the direction that you're moving. If that rectangle doesn't intersect with the button you're trying to move to, then that would explain why it's not working for you.


2. If the on-screen arrangement seems okay, you can pause your app in the debugger and ask the button you thought focus would move to why it isn't accepting focus by sending it the message "_whyIsThisViewNotFocusable"


3. If you can get a breakpoint to get hit within didUpdateFocusInContext:animationCoordinator: then you can use the Xcode QuickLook feature to see a visual representation of how the focus engine "sees" your UI.


For those last two, see the App Programming Guide (scroll to the bottom): https://developer.apple.com/library/prerelease/tvos/documentation/General/Conceptual/AppleTV_PG/WorkingwiththeAppleTVRemote.html

How do you send a button the message "_whyIsThisViewNotFocusable" in the debugger?

If your view is in a variable called myView, then type this in the LLDB console in Xcode when you're paused in the debugger:


po [myView _whyIsThisViewNotFocusable]


If your view isn't in a variable with a name, you can use the pointer address as long as you cast it to a UIView pointer first:


po [(UIView *)0x14b644d70 _whyIsThisViewNotFocusable]

So I aligned my buttons and NOW I CAN "navigate between them". If the buttons are just scatterered around the screen you can't navigate beween them, so alignment is important?

Glad it's working for you now!


Yes, alignment is important. If, for some reason, you just can't change the arrangement of your buttons, you can use a UIFocusGuide to "cheat" with the alignment. With a focus guide, you don't have to have the button aligned but instead get the focus guide aligned and configure the focus guide to point to your button as it's preferredFocusedView. See this page for the documentation about focus guide: https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIFocusGuide_Class/index.html==

Navigate Between Buttons Simulator not working
 
 
Q