【问题标题】:Segue Unwind back to the last specific View controllerSegue Unwind 回到最后一个特定的视图控制器
【发布时间】:2013-04-06 20:54:06
【问题描述】:

有没有办法让一个按钮回到特定的视图控制器?例如,假设我有 ViewController A 和 B。两者都以模态方式连接到 ViewController C。现在我了解如何将展开返回到以前的视图控制器之一 (As was explained here),但是我如何返回到呈现的特定视图控制器VC C?

总而言之,我想弄清楚的是...... 如果 A 连接到 C,那么我想在选择按钮时回到 A。如果 B 连接到 C,那么我想在选择按钮时回到 B。

【问题讨论】:

    标签: objective-c xcode uiviewcontroller storyboard segue


    【解决方案1】:

    您应该使用标准方式从模态转场返回。把它放在你的“后退”按钮中......

    [[self presentingViewController] dismissViewControllerAnimated:YES];
    

    这不使用情节提要或返回的segue,只是代码。

    【讨论】:

    • 或者在 Swift 中:self.presentingViewController!.dismissViewControllerAnimated(true, completion: nil)
    【解决方案2】:

    您可以使用presentingViewController 'title' 属性将展开过程引导到所需的原始ViewController。此解决方案还允许您将数据从 ViewController C 传递到 ViewController A 和 B。

    1) 选择 V​​iewController A 故事板画布顶部的 View Controller 按钮(黄色的)。

    2) 在 Attributes Inspector(View Controller 部分)中,给 ViewController A 一个标题。

    3) 在 ViewController A 中包含以下代码:

    @IBAction func returned(segue: UIStoryboardSegue) {
       // Don't need any code here 
    }
    

    4) 对 ViewController B 重复步骤 1、2 和 3。

    5) 重写 ViewController C 中的 prepareForSegue 函数如下:

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {   
        if self.presentingViewController!.title! == "ViewControllerATitle" {
            let destination = segue.destinationViewController as! ViewControllerA
            destination.someFunction(someArgument)
        } 
        else if self.presentingViewController!.title! == "ViewControllerBTitle" {
            let destination = segue.destinationViewController as! ViewControllerB
            destination.someFunction(someArgument)
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-13
      • 2014-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多