3

I have two View Controller. In the first I do some stuff and then I can push the second View Controller by clicking a button (the button connected with the other ViewController in the storyboard). There I can do some settings and so on. I get back to the first View Controller with the button "Done". But then the ViewDidLoad method is called again and all the "stuff" (text in textfields, ...) is gone.

I hope you guys understand my problem.

Why? And how can I disable this?

iDev
  • 23,310
  • 7
  • 60
  • 85
user1554681
  • 105
  • 8

2 Answers2

1

How are you going back to the first view controller from the second one? I think your problem is you're re-instantiating the first view controller when the user hits "Done".

Instead, you should be using either "popViewControllerAnimated" or "dismissViewControllerAnimated" to go back to the first view controller.

e.g: (one of these 2 should work):

[self.navigationController popViewControllerAnimated:YES];
[self dismissViewControllerAnimated:YES completion:nil];
melsam
  • 4,947
  • 1
  • 22
  • 23
  • I don't have a navigationController. In the storyboard I drag it with a right click on the button "Done" to the first ViewController. – user1554681 Feb 27 '13 at 21:26
  • +1: I agree, it sounds like he isn't popping/dismissing the view controller appropriately but is instead creating a new instance of it, which would indeed call `viewDidLoad:` "again" (it's a new instance after all) – JRG-Developer Feb 27 '13 at 21:27
  • ohh... nice. I just tested it with "[self dismissViewControllerAnimated:YES completion:nil];" and it worked. But now the problem is, if I add text in a textfield in the second ViewController, than go back to the first, then again in the second one, the text is gone... – user1554681 Feb 27 '13 at 21:33
0

Maybe the firstViewController is unLoaded because of receiving memory warning. So when it opened again, it calls ViewDidLoad

Hossam Ghareeb
  • 7,063
  • 3
  • 53
  • 64