Search code examples
iosuiviewcontrollerparent

How to find out which is the parent (previous) uiviewcontroller? iphone


For example I have 3 UIViewControllers A, B, C.

I go trough UIViewControllers like this:

 A -> B -> C -> B -> A

When we arrive in the UIViewController B, I want to know if I arrived in B from A or from C.

So I want to know which is the previous UIViewController of B.


Solution

  • above other answer, you can maintain a tag for the view controller you're coming from, make a property of int tagViewControllerFrom, and set it when you push to B, from A or C, for A set something 1, or for C set something 2, both should be distinguished, then in viewDidLoad of B you can check it using if condition and do accodingly.