Doug Smith
Doug Smith

Reputation: 29316

At the current storyboard, how do I find which view controller segued the view there?

Say I'm at a specific view controller that one of several view controllers could have brought the user to. How do I find which one it is? Because I need to add a specific button in the toolbar for if it segued from a specific view controller.

(In prepareForSegue: you can find the destination view controller, I'm wondering if there's a way to find the opposite, the source view controller, so to speak.)

Is the only way to store it as a property of the class?

Upvotes: 0

Views: 435

Answers (2)

Jelle
Jelle

Reputation: 1034

Why do you need the controller that brought the user there? If you need it there is probably some meaning to it as well. The normal way to do this, is usually a delegate on the destination controller, that gets set by the caller in prepareForSegue. That way the destination controller can inform its delegate of changes, updates, needed actions or whatever.

Here is some example code from Apple that explains about coordination between view controllers, including this delegate solution in prepareForSegue: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ManagingDataFlowBetweenViewControllers/ManagingDataFlowBetweenViewControllers.html

Upvotes: 2

rdelmar
rdelmar

Reputation: 104082

In the destination view controller, you need to create a property to point to the controller that segued to it (or it could be a BOOL or number depending on how you're implementing). In prepareForSegue, you can just use self to set the value of the property.

Upvotes: 0

Related Questions