Is it possible to add same UIViewController Class to another tab

26 Views Asked by At

Is it possible to added same FirstViewController class to UITabBarController -> tabBar -> 4 items added.

ZeroTabBarController -> FirstViewController -> FirstViewController -> ThirdTabBarController.

1

There are 1 best solutions below

0
Fahim Parkar On

Yes, you can do what you are trying to do.

To achieve this, you have to trick it little bit.

Below is what you will structure

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

Now in DummyOneVC, in viewWillAppear you will transition to FirstVC but without animation so that user will not know what you are doing behind.

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)    
}