swift - 如何知道使用 Swift 使用了哪个 segue?

标签 swift segue

我有一个主 viewController 和一个 detailsViewController。 detailsViewController 有 2 个按钮。这两个按钮都是返回到主 Controller 的转场,但我想根据使用的转场自定义主 viewController。检查使用哪个 segue 到达 viewController 以便可以根据它自定义主 viewController 的最佳方法是什么? - 如果 segue1 导致主 viewController,那么我想隐藏 label1。如果 segue2 指向主 viewController,那么我希望隐藏 label2。

最佳答案

在主视图 Controller 中创建一个变量,类似于

var vcOne : Bool = true

现在在 DetailsViewController 中

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
        if segue.identifier == "segue_one"
        {
            let mainVC : MainViewController = segue.destinationViewController as! MainViewController
            secondVC.vcOne = true


        }
        else if segue.identifier == "segue_two"
        {
           let mainVC : MainViewController = segue.destinationViewController as! MainViewController
            secondVC.vcOne = false
        }

    }

现在在主视图 Controller 中

     override func viewWillAppear(animated: Bool) {
             super.viewWillAppear(animated)

             //Now check here for which segue
            if(vcOne)
           {
            // implement for button one click

            }
           else
           {
              // implement for button two click 

           }


        }

希望对你有帮助

关于swift - 如何知道使用 Swift 使用了哪个 segue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36276702/

相关文章:

ios - 如何以编程方式在 swift ios 中自动将光标从一个文本字段移动到另一个文本字段?

ios - 核心数据 swift : How to save and load data?

ios - Swift 中的重新发送 OTP 计时器功能

ios - 未在自定义 UIButton 上设置图像

macos - 从 NSToolbar 覆盖 prepareForSegue

ios - 如何在由 UITabBarController 分隔的两个 View Controller 之间传递数据?

iOS 首次启动之旅——检测应用是否首次启动

ios - 声音停止播放后如何执行 segue

iphone - 尝试在从 segue 返回时运行代码

json - 执行segue swift 4