是否可以将相同的 UIViewController 类添加到另一个选项卡

Is it possible to add same UIViewController Class to another tab

提问人:kiran 提问时间:9/21/2022 更新时间:9/21/2022 访问量:21

问:

是否可以将相同的FirstViewController类添加到UITabBarController -> tabBar -> 添加了 4 个项目。

ZeroTabBarController -> FirstViewController -> FirstViewController -> ThirdTabBarController。

swift uitabbarcontroller uitabbaritem

评论


答:

0赞 Fahim Parkar 9/21/2022 #1

是的,你可以做你想做的事。

要做到这一点,你必须稍微欺骗它。

以下是您将构建的内容

Tabbar
  - DummyOneVC - FirstVC
  - SecondVC
  - DummyThreeVC - FirstVC
  - FourthVC

现在在 中,您将过渡到但没有动画,这样用户就不会知道您在后面做什么。DummyOneVCviewWillAppearFirstVC

DummyOneVC的

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    let destVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FirstVC") as! FirstVC
    self.navigationController?.pushViewController(destVC, animated: false)    
}