抱歉,如果标题令人困惑。我的 tabBar 中的选项卡上有一个创建帖子工作流程。最后,有一个“创建”按钮来发布帖子。以下是按下该按钮所附的代码:
@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 - 创建帖子工作流程的第一步,这样当用户选项卡返回到此工作流程时,他们将从头开始并且不会返回到createPost ViewController(最后一步)这就是现在正在发生的事情。
我如何在“幕后”执行此segue以便发生这种情况?
最佳答案
我通过在 createPost 按钮中执行“展开”segue 来实现这一点...
@objc func postButtonPressed() {
//post code//
...
performSegue(withIdentifier: "unwindToCamera", sender: nil)
}
我在界面生成器中添加了展开转场。然后在 CameraViewController 中我有:
@IBAction func unwindToCamera(sender: UIStoryboardSegue) {
self.tabBarController?.selectedIndex = 0
self.tabBarController?.tabBar.isHidden = false
}
将 selectedIndex 切换回主屏幕。然而,当您返回到相机选项卡时,由于之前完成了展开转场,我们又回到了相机 View Controller 。这是期望的行为。一个缺点是,我无法在不更改所选 tabBar 索引的情况下放松相机序列,但我的应用程序目前没有理由让我这样做。
关于ios - 不在事件 View Controller 上时如何执行 segue "behind the scenes"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52683895/