如何通过单击按钮触发从标签栏项目到另一个标签栏项目的转场?

How to trigger a segue from a tab bar item to another by clicking a button?

我正在尝试在选项卡视图控制器内创建一个选项卡视图项,它不仅通过点击选项卡栏中的项目而且通过我自己创建的按钮切换到其他选项卡视图项。

从您的 VC 之一的标签栏控制器,您可以通过访问 parent 来访问标签栏控制器。如果你的 VC 也嵌入了导航控制器,你需要访问 parent.parent.

// assuming "self" is embedded in a navigation controller
if let tabBarController = self.parent?.parent as? UITabBarController {

}

拥有标签栏控制器后,您可以将其 selectedIndex 设置为转到您想要的任何标签:

tabBarController.selectedIndex = 1 // second tab

来自 selectedIndex 的文档:

...Setting this property changes the selected view controller to the one at the designated index in the viewControllers array...