如何更改 WatchKit 应用程序中的初始控制器?

How to change initial controller in WatchKit app?

在我的 WatchKit 应用程序中,我需要根据包含 iOS 应用程序的状态显示两个界面控制器之一。 Page-Based 和 Hierarchical 界面都不符合我的需要。

在 UIKit 中,我可以更改 window 的 rootViewController。我可以在 WatchKit 中做类似的技巧吗?

有没有办法以编程方式切换到不带动画的不同界面控制器并使其成为 "initial controller"?

如果你的app中只有2个Interface Controller,那么你可以使用Groups,一次显示一组,其他的根据你的情况隐藏。

在 运行 时间,修改项目排列的唯一方法是 show/hide 您已经使用界面生成器添加的元素。

希望对您有所帮助。

let rootControllerIdentifier = "FirstInputInterfaceController"

WKInterfaceController.reloadRootControllers(withNames: [rootControllerIdentifier], contexts: nil)