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];
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()
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.
You have to call your API method in viewWillAppear()
. So, whenever you come back from any viewController, your updated server data will reload itself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.