1

I have a navigationControll with several views. Everything works properly. I now want to show an alert in the parent view, after i call the method [self.navigationController popViewControllerAnimated:YES]; in the child view. I configured the alert to show on the parent's view controller viewDidLoad. But what i acknowledge is that this is only called the first time the view is called. Is there any method called each time i go back to this view? thks!

StinkyCat
  • 1,236
  • 1
  • 17
  • 31

2 Answers2

5

I had to remove the -(void)viewDidAppear:(BOOL)animated; in order for this to work:

-(void)viewWillAppear:(BOOL)animated
{
  //YOUR CODE HERE (mine was the alert showing up)
}

Now the alert works perfectly.

StinkyCat
  • 1,236
  • 1
  • 17
  • 31
0

You should try -(void)viewDidAppear:(BOOL)animated;. Don't forget to call [super viewDidAppear:animated]; at some point in your implementation.
Another way to catch this event is to use a delegate method :

-(void)navigationController:(UINavigationController *)navigationController
      didShowViewController:(UIViewController *)viewController
                   animated:(BOOL)animated;

You can find more information visiting UINavigationControllerDelegate Protocol Reference.

  • -(void)viewDidAppear:(BOOL)animated; didn't do anything. -(void)viewWillAppear:(BOOL)animated; is called everytime the view appears on the screen – StinkyCat Jul 24 '11 at 15:51
  • the difference between `viewWillAppear` and `viewDidAppear` is just the time when the method gets called either respectively before and after the view appear. –  Jul 24 '11 at 16:23
  • well.. for me viewDidAppear just didn't work. Or is it that i can only have one of those in each view? – StinkyCat Jul 24 '11 at 16:25
  • both of them are `UIViewController` methods, and there is no contradiction using those two at the same time. –  Jul 24 '11 at 16:28