user6825883 user6825883 - 1 month ago 20
iOS Question

Show Taps in TapBarViewController

I have a

TapBarViewController
with three Taps in my project.

Now I am trying to put a normal
FirstViewController
in front of the
TapBar ViewController
when the application launches.

The
FirstViewController
should have three buttons for one of the individual Taps of the
TapBarViewController
.

How can I show the individual Taps of the
TapBarViewController
by pressing one of the three buttons?

Screenshot

Answer

This is the exact answer you are looking for.

Steps:

  1. Add a UIViewcontroller and embed with UINavigationViewController (Editor -> EmbedIn -> NavigationController).
  2. Add Three button + 1 Button (Navigate to TabViewController).
  3. Drag and drop UITabBarController to the storyboard it comes with one default ViewController and place a UILabel named as 'ButtonOneClicked'.
  4. Create Two more ViewControllers and named as 'ButtonTwoClicked' and 'ButtonThreeClicked'.
  5. Connect 'ButtonOne' with FirstViewController and set segue as Show and repeat the same for rest two.
  6. Click on each segue and provide an unique Identifier name.
  7. Then connect the UITabBarController with each UIViewController and choose viewcontrollers
  8. Create a ButtonAction to the Tab Button.
  9. Copy paste the below code in that action.

    @IBAction func tabClicked(_ sender: Any) {
        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        appDelegate.window = UIWindow(frame: UIScreen.main.bounds)
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let initialViewController = storyboard.instantiateViewController(withIdentifier: "Tab") as! UITabBarController
        appDelegate.window?.rootViewController = initialViewController
        appDelegate.window?.makeKeyAndVisible()}
    

Please find the storyboard structure below

Hope this helps you!!