如何在 UITabBarController 中独立处理视图控制器?

How to handle a view controller independantly in UITabBarController?

我的应用程序的根是一个 UITabBarController,有 5 个部分,每个部分包含一个 UINavigationController

我还想在应用程序中添加聊天功能,可以通过应用程序每个导航栏中的 rightBarButton 访问该功能。我希望它在屏幕上显示聊天 UIViewController,取消选择当前选择的选项卡栏项目并且不会丢失五个导航控制器的导航状态,即使是之前在点击聊天按钮之前选择的那个。我最好的选择是什么?

感谢您的 help/ideas。

第 1 步: 在故事板中添加 ChatViewController - 如果你想要一个导航栏,请将你的 ChatViewController 嵌入到导航视图控制器中。在您的 ChatViewController 中添加一个关闭的 BarButtonItem。

第 2 步:在您的 ChatViewController 中创建一个关闭操作,并与 StoryBoard 中的 BarButtonItem 绑定。

@IBAction func CloseAction(_ sender: UIBarButtonItem) {
    dismiss(animated: true, completion: nil)
}

第 3 步: 在 Storyboard 中,select 带有 rightBarButton 的导航控制器并选择 Present Modally 并连接到 ChatViewController 的导航控制器。

您可以转到 ChatViewController 而不会丢失任何导航控制器的导航状态。