Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference to the segue source view controller

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?

like image 578
StuartM Avatar asked May 30 '13 22:05

StuartM


People also ask

What is segue in uisplitviewcontroller?

This segue is relevant only for view controllers embedded inside a UISplitViewController object. With this segue, a split view controller replaces its second child view controller (the detail controller) with the new content. Most other view controllers present the new content modally.

How do I know which segue was triggered by the user?

During a segue, you can use the identifier to determine which segue was triggered, which is especially useful if your view controller supports multiple segues. The identifier is included in the UIStoryboardSegue object delivered to your view controller when the segue is performed.

What is a segue in Salesforce view controller?

For most view controllers, this segue presents the new content modally over the source view controller. Some view controllers specifically override the method and use it to implement different behaviors. For example, a navigation controller pushes the new view controller onto its navigation stack.

How do I access the destination view controller from the segue?

The segue, which is an object, is passed as a parameter to that method. Through its destination property, you can access the destination view controller. The destination view controller needs to declare a public stored property to receive data. First of all, let’s set up the destination view controller. @IBOutlet var imageView: UIImageView?


2 Answers

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;
like image 86
rdelmar Avatar answered Sep 30 '22 00:09

rdelmar


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.

like image 32
Tommy Devoy Avatar answered Sep 30 '22 00:09

Tommy Devoy