0

I have two view controllers: RootViewController and DetailViewController

I define a Push Segue to DetailViewController from RootViewController in Storyboard, and I set its ID to ShowDetailView. I can then set up various variables in DetailViewController using the method

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"ShowDetailView"]) {
    }
}

My Question: Is there a way to call a method (performed in RootViewController) when I resign from DetailViewController back to RootViewController? I'm using the following code to resign:

[self.navigationController popViewControllerAnimated: YES];
Apollo
  • 8,874
  • 32
  • 104
  • 192

1 Answers1

0

By default? No. You can build a delegate for this.

But instead, I think you can perform the code you want inside -(void)viewWillAppear:(BOOL)animated of your RootViewController.

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self myMethodHere];
}

The viewWillAppear method will be called exactly after your DetailViewController will be resigned.


EDIT: Like a said, no easy way to do this. Maybe the best way its really with a delegate. It really has to be AFTER the resign? If it can be before, you can get the reference of your rootViewController and execute your method BEFORE the resign, like this:

 RootViewController *rootViewController = (RootViewController*) [[self.navigationController viewControllers] objectAtIndex:0];
[rootViewController someMethod];
[self.navigationController popViewControllerAnimated: YES];

If you really want to be after, than you can create a flag and set to yes with the code above, and check this flag with an if inside viewWillAppear to execute your method, otherwise you cannot run from delegate.

Lucas Eduardo
  • 11,525
  • 5
  • 44
  • 49
  • the problem with that is that every time the view appears, this method will get called. That's inefficient if I only want the method to be called when I resign from DetailViewController. – Apollo Jul 31 '13 at 01:28