从编码按钮展开 segue - swift
unwind segue from coded button - swift
我正在尝试使用 unwind segue 从用户必须 select 一个选项的控制器返回:
在主控制器中,用户可以触摸一个按钮,将他们定向到第二个视图控制器,我在其中以编程方式构建按钮(选项)。当用户 select 其中一个按钮时,我希望他们返回到前一个控制器并传递按钮数据。
我找不到使展开转场正常工作的方法。
这是我在第二个视图控制器中的内容:
// 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
}
}
我将控制器链接到情节提要中的退出按钮(selecting prepareForUnwind
函数),并为 unwindSegue“BackToPhraseSegue
”
我错过了什么...
查看此答案的第二部分,确保您正确连接了 segue。
您要展开的功能需要在您要返回的 viewController 中。而不是 prepareForUnwind
,您需要在之前的 viewController(您要返回的 viewController)中使用 unwindToHere
:
@IBAction func unwindToHere(segue: UIStoryboardSegue) {
// And we are back
let svc = segue.sourceViewController as! TheViewControllerClassYouAreReturningFrom
// use svc to get mood, action, and place
}
我正在尝试使用 unwind segue 从用户必须 select 一个选项的控制器返回:
在主控制器中,用户可以触摸一个按钮,将他们定向到第二个视图控制器,我在其中以编程方式构建按钮(选项)。当用户 select 其中一个按钮时,我希望他们返回到前一个控制器并传递按钮数据。
我找不到使展开转场正常工作的方法。
这是我在第二个视图控制器中的内容:
// 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
}
}
我将控制器链接到情节提要中的退出按钮(selecting prepareForUnwind
函数),并为 unwindSegue“BackToPhraseSegue
”
我错过了什么...
查看此答案的第二部分,确保您正确连接了 segue。
您要展开的功能需要在您要返回的 viewController 中。而不是 prepareForUnwind
,您需要在之前的 viewController(您要返回的 viewController)中使用 unwindToHere
:
@IBAction func unwindToHere(segue: UIStoryboardSegue) {
// And we are back
let svc = segue.sourceViewController as! TheViewControllerClassYouAreReturningFrom
// use svc to get mood, action, and place
}