不在活动视图控制器上时如何执行 segue "behind the scenes"?

How to perform a segue "behind the scenes" when not on the active view controller?

抱歉,如果标题令人困惑。我有一个 create post 工作流程,它位于我的 tabBar 中的一个选项卡上。最后,有一个 "create" 按钮来发布 post。这是按下该按钮所附的代码:

@objc func postButtonPressed() {
    let tokens = self.tagsView.tokens()
    let tokensArr = tokens!.map({
        (token: KSToken) -> String in
        return token.title
    })
    if MyVariables.isScreenshot == true {
        PostService.createImagePost(image: self.screenshotOut!, timeStamp: self.postDate!, tags: tokensArr, notes: addNotesTextView.text ?? "")
    } else {
        PostService.createVideoPost(video: self.videoURL!, timeStamp: self.postDate!, thumbnailImage: self.thumbnailImage!, tags: tokensArr, notes: addNotesTextView.text ?? "")
    }
    self.tabBarController?.selectedIndex = 0
    self.tabBarController?.tabBar.isHidden = false

    //performSegue(withIdentifier: "ShowHomeViewController", sender: nil)
}

这是因为 tabBarController 切换回我的另一个选项卡。但我想要的是它也可以返回到 cameraView Controller - create post 工作流程的第一步,以便当用户返回此工作流程时,他们会从头开始并且不会来回到 createPost ViewController(最后一步),这就是现在发生的事情。

我如何执行此转接 "behind the scenes" 才能发生这种情况?

我通过在 createPost 按钮中执行 "unwind" segue 实现了这一点...

@objc func postButtonPressed() {
    //post code//
    ...

        performSegue(withIdentifier: "unwindToCamera", sender: nil)
    }

我在界面生成器中添加了 unwind segue。然后在 CameraViewController 中我有:

@IBAction func unwindToCamera(sender: UIStoryboardSegue) {
        self.tabBarController?.selectedIndex = 0
        self.tabBarController?.tabBar.isHidden = false
    }

将 selectedIndex 切换回主屏幕。但是,当您返回到相机选项卡时,由于之前完成的展开转场,我们又回到了相机视图控制器上。这是期望的行为。一个缺点是我无法在不更改所选 tabBar 索引的情况下对相机转场进行放松,但我的应用程序目前没有理由让我这样做。