简体   繁体   English

使用故事板 segue 后,标签栏未显示

[英]After using a storyboard segue the Tab bar is not showing

There are some similar questions but not exactly the same, and some are quite old.有一些类似的问题,但不完全相同,有些问题已经很老了。 Basically the tab bar is going missing after I'm doing a performSegue on a button press.基本上,在我按下按钮执行 performSegue 后,标签栏会丢失。

The view controllers are laid out in the storyboard but I'm putting the text and buttons into them programatically.视图控制器布置在故事板中,但我以编程方式将文本和按钮放入其中。 Segues 1 & 2 are storyboard segues which are the kind "Present Modally".转场 1 和 2 是故事板转场,属于“模态当前”类型。 In the top right view controller when one of the buttons are pressed it sets a variable and performs Segue 2. This is where the Tab Bar is not visible.在右上角的视图控制器中,当按下其中一个按钮时,它会设置一个变量并执行 Segue 2。这是 Tab Bar 不可见的地方。

Segue 3 is a relationship segue and you can see when it's selected (1st image) it shows the Tab Bar on "Second View". Segue 3 是一个关系 segue,您可以看到当它被选中(第一张图片)时,它会在“第二个视图”上显示标签栏。 But in the 2nd image it shows segue 2 selected and the Tab Bar is missing.但在第二张图片中,它显示选择了 segue 2 并且缺少标签栏。

I'm calling segue 2 like this:我像这样调用segue 2:

performSegue(withIdentifier: "ShowChapter", sender: self)

Based on what I've read I think perhaps I need a Navigation Controller somewhere.根据我读过的内容,我想我可能需要在某处使用导航控制器。 Currently I have no navigation controllers so to test my code I have to Stop execution and start again.目前我没有导航控制器,所以为了测试我的代码,我必须停止执行并重新开始。

If anyone can tell me how to have the Tab bar showing after segue 2 it would be much appreciated.如果有人能告诉我如何在 segue 2 之后显示 Tab 栏,我将不胜感激。

标签栏显示

标签栏不见了

Please uncheck Hide Bottom Bar on Push in storyboard.请取消选中在推入故事板时隐藏底部栏。

在此处输入图片说明

  1. Create a custom UITabbarController with an unwind @IBAction使用 unwind @IBAction 创建自定义 UITabbarController

     class CustomTabBarViewController: UITabBarController { @IBAction func unwindToVC2(segue: UIStoryboardSegue) { dismiss(animated: true) { self.selectedIndex = 1 } } }
  2. Create manual unwind segue in a modal presented view controller (ctrl-drag from File's Owner to Exit) and set it's identifier to "segueFromVCXToVC2"在模态呈现的视图控制器中创建手动展开 segue(按住 ctrl 从文件所有者拖动到退出)并将其标识符设置为“segueFromVCXToVC2”

  3. In modale presented view controller perform the custom unwind segue在模式呈现的视图控制器中执行自定义展开转场

    performSegue(withIdentifier: "segueFromVCXToVC2", sender: nil)

This will dismiss a modal view controller and select the second tab of the tabbar view controller这将关闭模态视图控制器并选择标签栏视图控制器的第二个选项卡

Adobels solution is on the right track, I tried it, but it didn't work. Adobels 解决方案走在正确的轨道上,我试过了,但没有奏效。 In the end what did the trick was a button on the top right View Controller which did a self.dismiss and then changed the tabbarcontroller selected index.最后的诀窍是右上角的视图控制器上的一个按钮,它做了一个 self.dismiss 然后改变了 tabbarcontroller 选择的索引。

Here is the function called by a button.这是按钮调用的函数。 (chapter selection button) (章节选择按钮)

@objc func selectChapter(button: UIButton) {
    CurrentChapter = button.tag
    self.dismiss(animated: false, completion: nil)
    if let tabBarController = self.presentingViewController as UITabBarController {
        tabBarController.selectedIndex = 1
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM