How to reload the previous view controller on back button?
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.
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, 2022Comments
-
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 toViewController
B.On B i can update the data which was shown onViewController
B.Now when data is updated on server i show an alert 'Update Success' on click of Ok i go to previousViewController
.But i don't see the updated data because i removed theViewController
B from stack but A is not reloded.Code for going back to ViewController A
[self.navigationController popViewControllerAnimated:YES];
-
iAnurag almost 9 yearsuse viewWillappear method
-
TechChain almost 9 yearswhere to use view will appear?@iAnurag
-
-
TechChain over 5 yearsThanks for your answer@Ranu