Reference to the segue source view controller

别等时光非礼了梦想. 提交于 2019-12-06 23:15:44

问题


Within my viewDidLoad I would like some custom code based upon the previous controller.

How can I access the segue source controller or the previous segue identifier in the destination controller's viewDidLoad to handle this?


回答1:


There is no way to get a reference to the segue that created you. You could create a property (sourceVC in my example) in the destination controller, and assign self to this property in the prepareForSegue method (in the source view controller):

[(DestinationVCClass *)segue.destinationViewController sourceVC] = self;



回答2:


You can just use [self presentingViewController] and you'll be able to access the VC that issued the segue. I usually like to couple it with isMemberOfClass: for a situation like this.




回答3:


You do the following in the unwinding segue method in the destination

self.source = (UIStoryboardSegue *)segue.sourceViewController;

Define source as a UIStoryboardSegue in the destination. The above line will give the source or the previous segue.



来源:https://stackoverflow.com/questions/16846760/reference-to-the-segue-source-view-controller

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