-1

Hi I am new to Stack Overflow so my apologies for any mistakes.I want to ask that whenever we pop to the previous view,how can we make the control go to the previous view viewDidLoad? In my application,it pops to the previous view but i want to reload the previous view so i want it to go to viewDidLoad.Thanks in advance. I have used the following code.

[self.navigationController popViewController:myViewController animated:YES];
4

3 回答 3

2

As far as I know, you can't do that. However, when you return to a view, the code in viewWillAppear will get executed (basically, the code in there is executed every time the view appears - as the name suggests).

Suggestion: split your code from viewDidLoad into 2 parts:

  1. one chunk of code that should only be executed once - which must be left there
  2. a second chunk of code that you want to be executed every time your view appears, which you'll move in viewWillAppear

Hope this helps !

于 2012-05-30T05:00:02.957 回答
1

When you pop a view and go back to previous view then 'viewWillAppearandviewDidAppear` methods of view controller are called.

Following is the calling hierarchy -

viewDidLoad- This method is called after the view controller has loaded its view hierarchy into memory.

viewWillAppear - This method is called before the receiver’s view is about to be added to a view hierarchy.

viewDidAppear- Notifies the view controller that its view was added to a view hierarchy.

Checkout UIViewController class reference for details of these view controller life cycle methods - http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIViewController_Class/Reference/Reference.html

So based upon requirement, you need to decide and what all UIElement you want to be loaded only once use in viewDidLoad and element on which you want to do refresh upon returning use viewWillAppear or viewDidAppear.

于 2012-05-30T04:58:49.437 回答
1

You can do that we a trick .

  1. Make a method and paste all your code from view did load in this method .

  2. Call that method from view did load .

  3. Call that method from view will appear .

This this not possible to call view did load but you can do all this from view will appear like view did load

Thanks

于 2014-04-03T05:44:23.240 回答