I have a Catalyst app running on macOS where I need to select and focus the first item in a collection view. By default a programmatically-selected item is only selected, not focused. To demonstrate what I mean, here is the app on launch...
And here is the app after I manually select the first item using the mouse or keyboard...
From what I understand, Catalyst uses the Focus Engine from tvOS to manage focus, and therefore applying the same concepts here should achieve the same result. However, I've had zero luck getting this working.
Things I have tried...
- Overriding
preferredFocusEnvironmentson the view controller and returning the collection view, and implementingindexPathForPreferredFocusedView(in:)in the collection view delegate. This works in so much as both methods are called, but has no effect on the outcome. - Overriding
preferredFocusEnvironmentsand returning the currently selected cell from the collection view. - Overriding
preferredFocusEnvironmentsand returning the cell at a hardcodedIndexPath(item: 0, section: 0), as per this Big Nerd Ranch article.
Unfortunately, none of these approaches has the desired outcome of actually focusing the selected item. Can anyone advise on how to achieve this?

