代码之家  ›  专栏  ›  技术社区  ›  L.Vl

回到选项卡BarController,swift

  •  2
  • L.Vl  · 技术社区  · 9 年前


    当前在我的视图中控制器: 上载 ,我的按钮仅在所有信息都已填写后才将数据发送到我的数据库,然后返回预览视图(表视图):
    self.navigationController?.popViewControllerAnimated(true)

    如果可能的话,我想回到我对 tabBarController 。我尝试了很多事情,比如直接在故事板上 向“TabBar控制器”显示模式段 ,但我返回TabBar时没有将数据发送到数据库,也没有签入填写的信息。。

    我该怎么做?

    谢谢

    2 回复  |  直到 9 年前
        1
  •  1
  •   xoudini    9 年前

    UITabBarController 有一个属性 selectedIndex 使用该选项卡可以切换所选选项卡。因此,在取消UploadViewController后完成时,您可以运行:

    self.tabBarController?.selectedIndex = 0 // Index to select
    

    最好为UploadViewController创建一个委托,以激发一个函数来完成previewVC中关于API调用完成的所有工作。

        2
  •  0
  •   David C.    4 年前

    (超迟的回应……如果有人有类似的问题,可能是在Swift的更高版本中,比如我的Swift 5,iOS 13.2)。步骤:

    1. 请确保为UITabBarController情节提要设置id,例如“TabBarViewController”
    2. 接下来,将以下内容添加到已连接到按钮的操作中:

    let ID_TABBAR = "TabBarViewCOntroller"

    @IBAction func returnToTabbar(_ sender: Any) {
            let tabBarController = self.storyboard?.instantiateViewController(identifier:ID_TABBAR) as! UITabBarController
            self.navigationController?.pushViewController(tabBarController, animated:true)
    }
    

    引用自 one of the responses from this post .

    更新: 如果选项卡栏视图控制器碰巧也是根视图控制器 returnToTabbar 上述方法可以是:

    self.dismiss(animated:true, completion:nil);
    self.navigationController?.popViewController(animated:true);
    

    (参考:见答案 here ,适用于Swift4,但在Swift5中运行良好)