Q:

Tell which ViewController pushed the DetailViewController

I have a DetailViewController, which is pushed/entered from RootViewController1 OR RootViewController2 through storyboard segues when Cell is selected.
The DetailViewController have a button with an IBAction. Can I program the action like:
If parent ViewController is RootViewController2, return. Else, perform Action.
Something like this:
-(IBAction)actionButtonPressed:(id)sender
{
    if (parentViewController == RootViewController2) {
        return;
    }

    //Else this is done:
    textLabel.text = @"Test";
}

But I'm not sure how to make it work, an example of this would be great. Let me know if you need more info!
EDIT:
Code now looks like this:
#import "RootViewController2.h"

...

-(IBAction)actionButtonPressed:(id)sender
{
    if([self.parentViewController isKindOfClass:[RootViewController2 class]]) {
        return;
    }

    //Else this is done:
    textLabel.text = @"Test";
}

But action is still performed from both views. Further suggestions?

A:

Just as @Matt mentioned, the view controllers are stored in an array. You can access the navigation controller array like this:
[self.navigationController.viewControllers lastobject ]
[self.navigationController.viewControllers objectAtIndex:2];

You can also get a reference to the parent view controller like this:
self.parentViewController
self.presentingViewController

regardless of how you obtain a reference to the parent, you still need to have a way to compare that reference.  You could use introspection like this  if ([object isKindOfClass:MyClass class]).  But somehow in that approach (using the view controller arrays) you need an object reference to each parent objects.  Its a tricky way to go.
Another possibly easier approach is to set a property value in the view controller before you segue to it in -(void)prepareForSegue .... block.  Something like this:
 MyClass *myClass = segue.destinationViewController;
 myClass.myLogicProperty = @"mommy";

and in the other segue from the other view controller
MyClass *myClass = segue.destinationViewController;
 myClass.myLogicProperty = @"daddy";

Now, when your button is pushed, you can just for against those values and then do the correct thing.
if ([self.myLogicProperty isEqualTo:@"daddy"]) {
   //take action
}
else if ([self.myLogicProperty isEqualTo:@"mommy"]) {
   //take action
}
else {
//do something if no match
}

Not knowing your specific needs, I'd recommend the latter and advise against trying to use the viewcontrollers array.
hope that helps.

