Reputation: 211
For example I have 3 UIViewController
s A, B, C.
I go trough UIViewController
s 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
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
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
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