问题描述
我设置了一个集合视图,其中 remembersLastFocusedindexPath
设置为 true。
CollectionView 被设计成具有嵌套的集合视图,
CollectionView
-> Section 1
--->Header
--->Cell nested with collectionview
-> Section 2
--->Header
--->Cell nested with collectionview
....so on....
也有分页。
现在,如果用户滚动到第 7 部分中的第 2 个项目并单击电视遥控器中的菜单,我正在将集合滚动到顶部。 [通过将内容偏移设置为 0 或滚动到第 0 个索引]
要求:滚动到第 0 个索引后,如果用户尝试关注第 0 个部分的第一个单元格,我希望焦点位于第 0 个索引处。
问题:但现在集合视图会记住上次聚焦的索引路径并滚动到第 7 部分中的第二项。
预期:在这种情况下,我不希望集合视图记住最后一个焦点索引路径。在所有其他情况下,应该记住它。即,滚动到顶部后,我想做类似
collectionView.scrollToTop()
resetFocus() //which should reset collection view's focus to initial index.
func resetFocus() {
//What should be written here to reset the focus of collection view.
}
解决方法
在您重置焦点后也尝试实现 indexPathForPreferredFocusedView
。文档 here。