如何切换 UITabBars 作为 UIButton segue 的结果?

How to switch UITabBars as a result of UIButton segue?

我有一个 UITabBar,目前有 4 个选项卡,效果很好。我需要导航到一组新的选项卡,就好像应用程序正在进入不同的模式一样。通过 navigationController 推送新的 UITabBar 是行不通的——它目前只是在旧的 UITabBar 之上添加了一个新的 UITabBar,并在旧的下面添加了一个新的 UINavigationBar。我会创建一个全新的 UIWindow,其 rootViewController 是我的新 UITabBarController 吗?

@objc func startSecondStory() {
    let newTabs = SecondaryTabBarController()
    navigationController?.pushViewController(newTabs, animated: true)
}

该代码是按下 UIButton 的操作。我不希望将新的 UITabBar 推到堆栈的顶部。我更喜欢它只是作为一个全新的 UINavigationController 与 rootView 作为 SecondaryTabBarController。

啊,我可以使用 present(_:animated:completion:)。但是,我仍然想知道是否有更有效的方法来减少内存使用。我认为这只是将新的 UITabBarController 弹出堆栈顶部而不删除旧的。

你可以使用(这会清除之前的)

self.navigationController?.setViewControllers([newTabs],animated:true)

//

UIApplication.shared.keyWindow?.rootViewController = newTabs