have vc1 which presents vc2 modally. vc2 has a save button which saves data and dismisses vc2. after vc2 has been dismissed, i want to reload the tableview on vc1. how can i do this?
reload tableview upon dismissing VC presented modally from current vc?
in viewWillAppear put in [myTableView relaodData];
Since viewWillAppear needs to check if the view has appeared after dismissing a vc, I took the following approach eventually...
- ade an unwind segue
- connected save button to this segue via the exit button of the vc
- reload tableview from unwind segue.
This may not work on an iPad.
The unwind segue didn't help as per my codes design and viewWillAppear is not being called after the modal view controller is dismissed. Even tried viewDidAppear. anything else i could try.
can i programatically trigger the unwind segue only after ensuring that the steps needed to be taken before calling the unwind segue are taken. that is, the steps inside save button (which in my case are saving settings required to load data in tableview in the presenting view controller)?
You could do both:
- in unwind segue or in viewWillAppear
- send notification when dismissing the VC. If the originating view is already loaded, it will receive notification to reload its table view.
And the 2 orders to reload are exlusive: only one will work depending on environment.
I saved the context, thus storing the settings. Then i called reload. Only after that i dismiss the vc2. Since the vc is presented modally, the vc1 was active in the background and it reloads the data. Notifications sounds like a great idea too. Ipads don't have modal presentation so it view will appear will work there, right?
I believe that on an iPad the modal view controller is presented as a popover so viewWillAppear does not get called in the parent - it never disappeared. (See my post above.) I believe that, on an iPhone, the parent viewWillAppear is called when the child view controller, presented modally, is dismissed - but you seem to have found otherwise. So as indicated above, another approach if you are running on both iPhone and iPad is to simply post an NSNotification in viewWillDisappear of the child view controller and receive that NSNotification in the parent by placing an observer for that notification in the parent viewDidLoad. The method that receives the notification executes reloadData. And, as you indicated, you can also do that when the data changes, you don't have to wait for viewWillDisappear.