9

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?

Tash Pemhiwa
  • 7,590
  • 4
  • 45
  • 49
StuartM
  • 6,743
  • 18
  • 84
  • 160

3 Answers3

7

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;
rdelmar
  • 103,982
  • 12
  • 207
  • 218
5

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.

Tommy Devoy
  • 13,441
  • 3
  • 48
  • 75
0

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.

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
Vaish
  • 1