Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload the previous view controller on back button?

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];
like image 438
TechChain Avatar asked Jul 30 '15 14:07

TechChain


2 Answers

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()

like image 135
iAnurag Avatar answered Oct 19 '22 10:10

iAnurag


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.

like image 23
Aaron Avatar answered Oct 19 '22 09:10

Aaron