indexPathForPreferredFocusedView(in:)
Asks the delegate for the table view’s index path for the preferred focused view.
Declaration
optional func indexPathForPreferredFocusedView(in tableView: UITableView) -> IndexPath?Parameters
- tableView:
A table view requesting the index path for preferred focus view.
Return Value
An index path for the preferred focus row, or the default preferred focus view.
Discussion
This functionality of this delegate method is equivalent to overriding UITableView class’s preferredFocusedView method in the UIFocusEnvironment protocol. If the UITableView class’s remembersLastFocusedIndexPath method is set to true, this method defines the index path that gets focused when the table view is focused for the first time.
The effects of this method may be ignored during or immediately after a view controller transition, such as a presentation dismissal or navigation stack pop. In such cases, the view controller attempts to restore focus to the item that was focused prior to the transition (for example, prior to the view controller being presented or pushed), which can take precedence over the effects of this method. To learn how to control or disable this behavior in the view controller, see restoresFocusAfterTransition.