ios - 不在事件 View Controller 上时如何执行 segue "behind the scenes"?

标签 ios swift uitabbarcontroller segue

抱歉,如果标题令人困惑。我的 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/

相关文章:

ios - 呈现新的 ViewController 后 Deinit UITabBarController

ios - 在应用内购买中,产品检索随机失败,错误代码为507

ios - 尝试使用 Swift 在 UITableView 的节标题的 UIView 内设置 UILabel 的文本

iphone - UITableViewCell 分配问题 - 单元格不为零

Swift,对于一些 UIViews 在点击时到他们的整体 Controller

ios - MKAnnotation Pin 不会拖动,即使设置为可拖动

iphone - 如何将自定义分隔线图像添加到 UITabBar?

ios - 查看旧导航栏和选项卡栏 Controller 的 Controller 问题

ios - 如何在 Swift 中使用 iOS SDK 8.3 静音 "UIRemoteNotificationType was deprecated"

iOS 应用程序登录网站