【发布时间】:2018-10-05 12:17:22
【问题描述】:
我正在处理具有多个视图控制器的项目,其中一个视图控制器具有许多文本字段和一个按钮,当您单击该按钮时,它会将您带到另一个具有地图视图的视图控制器。当用户在地图上选择一个地点,然后尝试返回第一个视图控制器时,之前填充的文本字段为空。
我怎样才能回到原始视图控制器并找到文本字段和选择器视图仍然保留最初在 segue 之前输入的相同值。
我是如何选择第二个 VC 的
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "toOnlyMap" {
let distenation = segue.destination as? onlyMapVC
distenation?.latitude = latitude
distenation?.longitude = longitude
}
}
@IBAction func toMapClicked(_ sender: UIButton) {
performSegue(withIdentifier: "toOnlyMap", sender: self)
}
这里是我如何解开第二个 VC
@IBAction func unwindToAdd(_ sender:UIStoryboardSegue) {
if latitude == 0.0 || longitude == 0.0 {
Helper.showAlert("Error", message: "you did not choose any place click back to dismiss this page", VC: self)
} else {
performSegue(withIdentifier: "backFromMap", sender: self)
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "backFromMap" {
let destination = segue.destination as? addNotificationVC
destination?.latitude = latitude
destination?.longitude = longitude
destination?.color = "Ggreen"
destination?.theHint = "you have choose the location"
}
}
【问题讨论】:
-
请添加您的代码并删除图片。
-
如何发布代码?
-
点击按钮“{ }”。之后你会看到:“在此处输入代码”。
-
我做了你的建议
-
backFromMapsegue 是 unwind segue 吗? IE。您是通过拖动到情节提要中地图场景的“退出”图标来创建它的吗?
标签: ios swift uiviewcontroller unwind-segue