【发布时间】:2023-04-08 11:22:01
【问题描述】:
我一直在尝试制作一个应用程序,当视图加载时,焦点会自动转到 UITableview 的第一个单元格。
我曾尝试使用 UIFocusGuide,然后在 prefferedFocusView() 方法中返回 tableView,但这不起作用。
然后我写了这段代码
var viewToFocus: UIView? = nil {
didSet {
if viewToFocus != nil {
print("called1 ")
self.setNeedsFocusUpdate();
self.updateFocusIfNeeded();
}
}
}
override weak var preferredFocusedView: UIView? {
if viewToFocus != nil {
print("called2 ")
return viewToFocus;
} else {
return super.preferredFocusedView;
}
}
在视图中确实加载了
self.viewToFocus = myTableView
但这并没有奏效。
【问题讨论】:
-
视图是否只包含表格视图?或者它也包含其他视图?
-
@Mr.UB 是的,它也有collectionview。当用户关注uitableview 中的项目时,我正在填充colllectionview。所以默认情况下,第一个单元格应该集中在 tableview 中!!!
-
当你说
prefferedFocusView时,你的意思是preferredFocusedView吗? -
请read the whole of this discussion 为问题添加紧急乞求。
标签: swift uitableview tvos