Select 来自嵌入式容器 UIViewController 的 UITabbarItem

Select UITabbarItem from embedded Container UIViewController

如何以编程方式 select 来自其他 ViewControllerUISegmentUITabbarController 项目?

ViewcontrollerA 有一个 UISegmentControl 和一个 ContainerView

UITabbarControllerB 嵌入在 ViewControllerAContainerView 中,它本身有两个 ViewControllers VCItemAVCItemB.

现在的问题是,我无法通过 UIViewcontrollerA 中的 SegmentControl 来更改 UITabbarControllerB 中的 VCItem

你可以在里面试试 ViewcontrollerA ( Swift)

if let tab = self.children.first as? UITabbarControllerB {
   tab.selectedIndex = // 0 or 1
}

( Objective - C )

if ([self.childViewController.firstObject isKindOfClass:UITabbarControllerB.self])
  UITabbarControllerB* tab = (UITabbarControllerB*) self.childViewController.firstObject;
  tab.selectedIndex = // 0 or 1
}