ios - 如何通过 Segue 在 vi​​ewWillAppear 中划分案例?

标签 ios swift segue appdelegate viewwillappear

目的

我正在制作应用程序来通过场景套件查看 3D 模型。
swift 4.0
Xcode 10.1

我想传输图像。我在 SCNViewController 中创建一个图像(使用 SCN View),然后移动到 ViewController。 我想在传输图像时划分情况。 我认为使用 Segue 更好。

enter image description here 继续细节 enter image description here

数组
我在 AppDelegate 中使用数组。因为我想在ViewController中添加并添加一个图像。当我移动到其他 ViewController 时,我不想删除图像。

问题

当我像下面这样写时,它会崩溃。我使用一个 func viewWillAppear。

View Controller

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

        if appDelegate.isNewSCNStampAdded == true{
             let scnstamp = appDelegate.scnstampArray.last!

             func returnToTop(segue: UIStoryboardSegue) {
                 if segue.identifier == "backtoFirstcoma" {
                 mainImageView.image = scnstamp
                 mainImageView.contentMode = UIView.ContentMode.scaleAspectFit
                 print("1")
             }else if segue.identifier == "backtoSecondcoma" {
                 print("2")
             }else if segue.identifier == "backtoThirdcoma" {
                 print("3")
             }else {
                 print("others")
             }
        }
        appDelegate.isNewSCNStampAdded = false
    }
}

(第二个想法)
我尝试了另一种方法。我做了一个“dividegoes”来区分。但这种方式也是行不通的。我无法在 viewWillAppear 的时间中捕捉到“dividegoes”的信息。

View Controller

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

        if appDelegate.isNewSCNStampAdded == true{
             let scnstamp = appDelegate.scnstampArray.last!

             switch dividegoes {
             case "goone" :
                 mainImageView.image = scnstamp
                 print("1")
             case "gotwo" :
                 secondImageView.image = scnstamp
                 print("2")
             case "gothree" :
                 thirdImageView.image = scnstamp
                 print("3")
             default:
                 print("Others")
             }
        }
        appDelegate.isNewSCNStampAdded = false
    }
}

SCNViewController

let dividegoes = "gozero"

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    switch segue.identifier {
    case "backtoFirstcoma" :
        let whiteVc = segue.destination as! ViewController
        whiteVc.dividegoes = "goone"
        print("go1")
    case "backtoSecondcoma" :
        let blueVc = segue.destination as! ViewController
        blueVc.dividegoes = "gotwo"
        print("go2")
    case "backtoThirdcoma" :
        let greenVc = segue.destination as! ViewController
        greenVc.dividegoes = "gothree"
        print("go3")
    default:
        print(“Others")
    }
}

这种情况下如何分案。
如果我删除“if-else”结构,它就会成功。但我需要以三种方式划分。

错误消息
其 View 不在窗口层次结构中!

我的想法

我无法在 viewWillAppear 中使用 Segue...? 也许我需要使用其他方式来划分案例...

最佳答案

override func prepare(for segue: UIStoryboardSegue, sender: Any?)

您应该考虑使用此函数而不是 viewWillAppear mate。

关于ios - 如何通过 Segue 在 vi​​ewWillAppear 中划分案例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54955604/

相关文章:

ios - subview 宽度 anchor 在 stackView 中不起作用

iOS Swift 转场

ios - 在 Web 服务调用 Swift3 完成时执行 segue

android - 来自react-native-vector-icons onpress的图标需要点击两次才能工作

ios - iOS CoreData 中的孤立对象

ios - 选择列表的顺序

iOS 无法在 master detail APP 中找到 segue

ios - Swift - UICollectionView 在一行中显示多个项目

ios - 如果未安装应用程序,则重定向到应用程序商店

swift - 在 Swift 中使用 Dispatch_Async 更新 UI