[英]unwind segue from coded button - swift
我正在尝试使用展开搜索从需要用户选择选项的控制器中返回:
在主控制器中,用户可以触摸将其定向到第二个视图控制器的按钮,在该控制器中,我以编程方式构建了按钮(选项)。 当用户选择按钮之一时,我希望他们返回到先前的控制器并传递按钮数据。
我找不到办法使放松的搜寻工作正常进行。
这是我在第二个视图控制器中拥有的:
// Tile touch handler function when button pressed
func selectedMood(sender:UIButton){
println("touching tile")
if(self.toShow == "mood"){
self.mood = moodAre[sender.tag - 1]
}
else{
self.action = actionAre[sender.tag - 1]
}
self.performSegueWithIdentifier("BackToPhraseSegue", sender: self)
}
@IBAction func prepareForUnwind(segue: UIStoryboardSegue) {
if (segue.identifier == "BackToPhraseSegue") {
let destination = (segue.destinationViewController as! PhraseController)
destination.mood = self.mood
destination.action = self.action
destination.place = self.place
}
}
// Data transmit between controller
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "BackToPhraseSegue") {
let destination = (segue.destinationViewController as! PhraseController)
destination.mood = self.mood
destination.action = self.action
destination.place = self.place
}
}
我将控制器链接到情节提要中的退出按钮(选择prepareForUnwind
函数),并为unwindSegue“ BackToPhraseSegue
”提供了一个标识符
我想念的是...
查看此答案的第二部分,以确保您正确连接了segue。
您要展开的功能必须位于要返回的viewController中。 取而代之的prepareForUnwind
,你需要一个unwindToHere
在前面的viewController(您返回到ViewController):
@IBAction func unwindToHere(segue: UIStoryboardSegue) {
// And we are back
let svc = segue.sourceViewController as! TheViewControllerClassYouAreReturningFrom
// use svc to get mood, action, and place
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.