Maria Stoica
Maria Stoica

Reputation: 211

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.

Upvotes: 0

Views: 121

Answers (3)

Hemang
Hemang

Reputation: 27050

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.

Upvotes: 2

Dr.Kameleon
Dr.Kameleon

Reputation: 22810

Try this one :

// In B

UIViewController* parentViewController = 
    (UIViewController*) [[self.view superview] nextResponder];

if ([parentViewController isEqualTo:viewControllerA])
{
}
else if ([parentViewController isEqualTo:viewControllerB])
{
}

Upvotes: 1

Saurabh Passolia
Saurabh Passolia

Reputation: 8109

you need to maintain a weak reference in your controllers (may be of id type) and can assign the parent controller to it when presenting the new controller

Upvotes: 0

Related Questions