2016-10-22 100 views
0

我在我的项目中有三个水龙头TapBarViewController在TapBarViewController中显示水龙头

现在我试图在启动应用程序时在TapBar ViewController之前放置正常的FirstViewController

FirstViewController对于TapBarViewController的单个分接头之一应该有三个按钮。

如何通过按三个按钮之一来显示TapBarViewController的单个分接头?

Screenshot

+0

你的问题不清楚。请提供一些截图。 –

+0

为了清晰起见,我添加了一张图片。 – user6825883

回答

0

这是你正在寻找确切的答案。

步骤:

  1. 添加UIViewcontroller并用UINavigationViewController(编辑 - > EmbedIn - > NavigationController)嵌入。
  2. 添加三个按钮+ 1个按钮(导航到TabViewController)。
  3. UITabBarController拖放到它带有一个默认ViewController的故事板,并放置一个名为'ButtonOneClicked'的UILabel。
  4. 创建另外两个ViewController并命名为'ButtonTwoClicked'和'ButtonThreeClicked'。
  5. 连接'ButtonOne'与FirstViewController并设置segue为Show并重复相同的休息二。
  6. 点击每个segue并提供一个唯一的标识符名称。
  7. 然后用各的UIViewController连接UITabBarController并选择viewcontrollers
  8. 创建ButtonAction到Tab按钮。
  9. 将该代码复制粘贴到该操作中。

    @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

希望这可以帮助你!

+0

这实际上并不是我想要的。我只想要一个初始的FirstViewController,它具有这三个按钮,这三个按钮称为三个TapBarViewControllers中的一个,除了应用程序重新启动时,我不想再显示FirstViewController。 – user6825883

+0

使用'tabClicked'按钮操作中的代码,并向UITabbarController发送一些独特的标签以打开它们各自的ViewController。 –

+0

self.tabBarController.selectedIndex = 1; // 1或2或3.在TabBarViewController的ViewWillAppear()中调用此行。 –