Swift 3+: 带有 TabBarController 的多个故事板。将 TabBarController Tab、Segue 设置为所需 ViewController

Swift 3+: Multiple Storyboards with TabBarController. Set TabBarController Tab, Segue to desired ViewController

在多个故事板中工作。从点 A->TabBarController(tab 2)->NavigationControllerA->StoryboardReference->NavigationControllerB->ViewControllerA->ViewControllerB 获取。不需要数据传递。

我的标签栏控制器设置在它自己的情节提要中,每个选项卡都通过导航控制器到达情节提要参考。然后故事板引用链接到另一个故事板(obv.),并通过导航控制器连接到 ViewControllerA。然后我想去 performSegue 到 ViewControllerB。这一切都是通过 UIViewController Extension 完成的。 根据我一直在阅读的内容,我应该这样处理:

    let tab = 2
    let sbOne = UIStoryboard(name: "Main", bundle: nil)
    let tabBarController = sbOne.instantiateViewController(withIdentifier: "TabBarController") as! UITabBarController
    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    appDelegate.window?.rootViewController = tabBarController
    tabBarController.selectedIndex = tab

    let sbTwo = UIStoryboard(name: "sbTwo", bundle: nil)
    let viewControllerA = sbTwo.instantiateViewController(withIdentifier: "ViewControllerA")
    performSegue(withIdentifier: "toViewControllerB", sender: self)

我收到 NSInvalidArgument:点 A "has no segue with identifier 'toViewControllerB'"

Swift 3+ 如果这是最佳答案,我会感到惊讶,但这是唯一有效的解决方案。我的一些问题源于缺乏理解。但我得出的概念是将功能分为两部分。设置 tabbarcontroller 选项卡,然后使用变量结构转到目的地。 我最终在 A 点设置了一个结构。

struct Destination {
    static var currentID = Int()
}

在按下按钮时,我会用这个设置变量,然后调用下面的函数:

Destination.currentID = currentID
goToViewControllerA()

然后使用我之前的部分代码,我可以将标签栏控制器设置为根视图控制器,然后转到所选 选项卡 上的 ViewControllerA(第一个视图控制器)。这是在 uiviewcontroller 扩展中完成的,但也可以在点 A.

中的函数中完成
goToViewControllerA(){
let tab = 2
let sbOne = UIStoryboard(name: "Main", bundle: nil)
let tabBarController = sbOne.instantiateViewController(withIdentifier: "TabBarController") as! UITabBarController
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController = tabBarController
tabBarController.selectedIndex = tab
}

接下来只需检查是否设置了 struct static var,然后转到目标控制器 (ViewControllerB)。这是在 ViewControllerA 中完成的,或者如果你必须通过多个视图控制器进行 segue,你可以在 viewdidload 中使用它在每个 viewcontroller 上建模你的函数。

If Destination.currentID != Int() {
    performSegue(withIdentifier:“toViewControllerBSegue”, sender:self)
}

如果有更好的方法,我很乐意学习。