答案 0 :(得分:2)
我认为你搜索的内容是放松的。
你可以在Apple的这篇文章中找到关于segues的好消息: https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/UsingSegues.html
对你来说特别有趣的应该是“创造一个放松的争论”部分。
答案 1 :(得分:1)
1. Give your segue a identifier, "make sure the identifier should be created from Controller"
2. use this function
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "yourIdentifier" {
let dvc = segue.destination as! yourVC
`// pass data
dvc.data = data
}
}
答案 2 :(得分:1)
您可以使用它的覆盖方法传递数据
1)在storyBoard中应用segue.identifier
2)在行动中添加self.performSegue(withIdentifier:"addTask" , sender: indexPath)
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "addTask" {
let taskData:Task?
let vc = segue.destination as! AddTaskVC
vc.taskData = taskList[indexpath.row]
vc.isUpdateTask = isEditTask
}
}
答案 3 :(得分:0)
将segue从第一个控制器设置为第三个时,可以使用此功能。在创建segue时检查标识符名称。
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
{
if segue.identifier == "yourIdentifier1"
{
let nextScene = segue.destination as? UIViewController
nextScene.stringUserName = "Mike"
}
else if segue.identifier == "yourIdentifier2"
{
let laterScene = segue.destination as? UIViewController
laterScene.count = 5
}
}
如果仍然发现错误,请显示错误