Unwind Segue - Where to Drag Exit?

半世苍凉 提交于 2019-12-11 11:34:23

问题


I am trying to understand how the unwind segue works. First I created 3 ViewControllers.

GlobalVC
 -LoginVC
 -RegisterVC 

I set the initial page the GlobalVC (only authenticated user can see). I set a segue from:

GlobalVC to LoginVC called globalToLogin and LoginVC to RegisterVC called loginToRegister. Here is my storyboard:

For the registerToLogin direction, I used this work-around (in RegisterVC), but looks a bit ugly.

@IBAction func unwindToLogin(sender: AnyObject) {
    //Dismiss View
    dismissViewControllerAnimated(true, completion: nil)
}

However, now I am trying to direct from LoginToGlobal

First, I selected Login button, dragged it to LoginVC:

@IBAction func loginButton(segue: UIStoryboardSegue) {
    performSegueWithIdentifier("unwindToGlobal", sender: self)
}

After setting segue: UIStoryboardSegue, now it gets available to right-click on Exit. But, I got confused here. Whatever I tried to drag the circle inside Exit to, it gives an error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', >reason: 'Receiver (0x7fdd2068a480>) has no segue with identifier 'unwindToGlobal''

Where should I drag the circle on? ( I keep seeing Unwind segue to 'Exit' )


回答1:


The unwind action method is defined in the destination view controller (e.g. in GlobalVC).

@IBAction func unwindToGlobal(segue: UIStoryboardSegue) {
     // this may be blank
}

And then, when you're hooking up the button to this action, you don't drag to the code sample, but rather to the "exit outlet" icon above the scene:

See this answer for more screen snapshots.



来源:https://stackoverflow.com/questions/34013064/unwind-segue-where-to-drag-exit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!