gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 05:58:02 24 4
gpt4 key购买 nike

目的

我正在制作应用程序来通过场景套件查看 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com