How to reload the previous view controller on back button?

10,636

Solution 1

I assume you are sending a web call from viewDidLoad(). So in order to update your viewController A Add your web call method in viewWillAppear()

Solution 2

The state of your "data" on view controller A has not changed and you need to refresh it. If you're fetching data for view controller A within -viewDidLoad, try moving it to a different life cycle method like -viewWillAppear.

Remember, -viewDidLoad gets called only when the view controller loads which happens once, however -viewWillAppear gets called before it appears which will happen often if you're hopping back and forth between views.

Solution 3

You have to call your API method in viewWillAppear(). So, whenever you come back from any viewController, your updated server data will reload itself.

Share:
10,636
TechChain
Author by

TechChain

I have 4+ of experience of overall experience.Currently working on Hyperledger Fabric blockchain framework. I have strong knowledge of Objective c, Swift.I have developed lot of apps from chat app, finance apps,location & map based apps.

Updated on July 22, 2022

Comments

  • TechChain
    TechChain almost 2 years

    I have two view controller A & B.On ViewController A i am displaying data from server.I have nav button Update to go to ViewController B.On B i can update the data which was shown on ViewController B.Now when data is updated on server i show an alert 'Update Success' on click of Ok i go to previous ViewController.But i don't see the updated data because i removed the ViewController B from stack but A is not reloded.

    Code for going back to ViewController A

      [self.navigationController popViewControllerAnimated:YES];
    
    • iAnurag
      iAnurag almost 9 years
      use viewWillappear method
    • TechChain
      TechChain almost 9 years
      where to use view will appear?@iAnurag
  • TechChain
    TechChain over 5 years
    Thanks for your answer@Ranu