Unwind segue not being triggered

白昼怎懂夜的黑 提交于 2019-12-13 04:29:40

问题


I have a storyboard that has a starting view controller that presents other modal view controllers.

Say view controller A is the startingViewController, and view controller B is the modally presented view controller.

How can I trigger the unwind segue from B back to A, from ViewController A ( not just from a button located on ViewController B)?

The button works to perform the unwind segue , but when I try to perform it programmatically using

[self performSegueWithIdentifier:@"ReturnToStart" sender:self]

an error occurs:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<StartViewController: 0x1ed4b9b0>) has no segue with identifier 'ReturnToStart''

What I don't understand is that the unwind segue is working fine when I press a button on the modal view controller, but the segue just can't be found when I attempt to trigger it from another ViewController (The identifier is correct in storyboard).

Is there any way of accessing all of the segues from my startingViewController or is my structure fundamentally wrong?


回答1:


The segue "belongs" to the source View Controller, so that's why you get that error message. Segues are intended to be called from the source view controller.

If you want to dismiss viewControllerB from A, don't use a segue, just use:

dismissViewControllerAnimated:completion:


来源:https://stackoverflow.com/questions/16405937/unwind-segue-not-being-triggered

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