在UISplitViewController中,默认情况下,焦点设置在TableView上。有没有办法让我覆盖它,以便重点关注DetailViewController?
启动应用程序时,我可以将焦点更改为按钮而不是TableView单元格吗?
答案 0 :(得分:1)
找到解决方案:
override weak var preferredFocusEnvironments: [UIFocusEnvironment] {
get {
let controllerToFocus = viewControllers[1] as? ViewController
return [(controllerToFocus?.view)]
}
我们需要调用setNeedsFocusUpdate()和updateFocusIfNeeded():
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
self.setNeedsFocusUpdate()
self.updateFocusIfNeeded()
}