问题描述
我需要指定哪个单元格应该获得焦点.
I need to specify which cell should receive focus.
根据 Apple 文档,如果 remembersLastFocusedIndexPath
属性为 false
或没有保存的索引路径,则应调用 indexPathForPreferredFocusedView
委托方法因为之前没有单元格被聚焦.
According to Apple Documentation the indexPathForPreferredFocusedView
delegate method should be called if the remembersLastFocusedIndexPath
property is false
, or if there is no saved index path because no cell was previously focused.
在我的情况下,我在 UIViewController
中使用集合视图并将 remembersLastFocusedIndexPath
设置为 false
但 indexPathForPreferredFocusedView
没有被调用.
In my case I am using a collection view in a UIViewController
and setting remembersLastFocusedIndexPath
to false
but indexPathForPreferredFocusedView
is not being called.
如何解释这种行为?
推荐答案
您应该将 remembersLastFocusedIndexPath
设置为 true
.
You should set remembersLastFocusedIndexPath
to true
.
collectionView.remembersLastFocusedIndexPath = true
这篇关于indexPathForPreferredFocusedView 没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!