2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ViewcontrollerからTabBarControllerへコードで移動する

2
Last updated at Posted at 2021-01-26

ViewControllerからTabBarControllerに移動する

まず、最初に下の図のようにViewControllerからTabBarControllerに紐づいてた緑のViewControllerに遷移しても、ViewControllerへの移動なので、下のタブが表示されません。だから、TabBarViewControllerへ移動する必要があります。

コード

ViewController.swift
import UIKit

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    @IBAction func FromViewControllertoTabBarController(_ sender: Any) {
        
        let storybord=UIStoryboard(name: "Main", bundle: nil)
        let TabBarController=storybord.instantiateViewController(withIdentifier: "TabBarController") as! UITabBarController
        //[0]が緑のViewControllerで[1]にすると赤のViewControllerに遷移する
        let ViewController=TabBarController.viewControllers?[0] as! FirstViewController
        //TabControllerに遷移した時に最初にどの画面を表示するかを選択する
        TabBarController.selectedViewController=ViewController
        TabBarController.modalTransitionStyle = .crossDissolve
        TabBarController.modalPresentationStyle = .fullScreen
        self.present(TabBarController, animated: true, completion: nil)
    }
    
}

赤色のViewControllerにはFirstViewControllerクラスが紐づいています。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?