Asks the delegate for the index path of the cell that should be focused.
- iOS 9.0+
- tvOS 9.0+
The collection view object requesting this information.
The index path of the preferred cell. The index path you specify must correspond to a valid cell in the collection view.
When focus is about to change to a collection view, the collection view must pick which of its subviews should receive that focus. If the collection view’s
remembers property is set to
true, the collection view returns the index path of the cell that was last focused. If the
remembers property is
false, or if there is no saved index path because no cell was previously focused, the collection view calls this method so that you can specify which cell should receive focus. If you do not implement this method, the collection view returns an appropriate cell.
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
If you subclass
UICollection, you can also implement the same behavior by overriding the
preferred property, which is defined by the
UIFocus protocol and adopted by all views.