3

I have three viewcontroller. when I get to the third viewcontroller, I use poptorootviewcontroller to pop to my first view controller, but when I use popviewcontroller in my third viewcontroller (i want to go back to my second viewcontroller) its poping but all the info that I edit in my second viewcontroller are there, and I want the secondviewcontroller to be new (reset this viewcontroller), like this viewcontroller to be reloaded. here is my code in the third viewcontroller:

-(IBAction)playAgain:(id)sender
{
   [self.navigationController popViewControllerAnimated:YES];
}

how can I do it? thanks!

Larme
  • 24,190
  • 6
  • 51
  • 81
user1492776
  • 280
  • 2
  • 7
  • 14
  • You could just do this from within the second view controller. When it pushes the third view controller, have it reset all its data. Then, if the user pops back to it, it will look like a new one. – Jason Coco Jul 08 '12 at 16:53
  • no, it is not working, maybe because when i use push view controller in my second view i also "send" to my third viewcontroller some variables... – user1492776 Jul 08 '12 at 17:02

1 Answers1

5

In the second viewcontroller, you should write a method viewWillAppear like below,

-(void) viewWillAppear:(BOOL)animated
{
     [super viewWillAppear:animated];
     //set initial values here  
}

This method will call when your controller is about to appear. So while third viewcontroller will get popped, this method will get called and you can reset values.

Apurv
  • 17,116
  • 8
  • 51
  • 67