How to call reload table view after you call rejectViewController function in swift?
My question is almost identical to the one found here: How to call viewDidLoad after [self rejectModalViewControllerAnimated: YES].
and I'm sure the answer is exactly what I need. I have a ViewController (let's say A) has a task list. When you click on a task in the table view in A, it calls a different view, ViewController (B) by default. When I have finished the task on B, I want to return to A by calling the rejectViewController function, but how do I reload the table?
The data is loaded into the table from the REST API, so I don't think just deleting that row will work. I will need to call the REST API to get the task list and then reload the table view.
I am not very knowledgeable about Obj C, so it is difficult for me to translate this. This is what I think needs to be done.
Make the protocol for the B ViewController delegate. Make A ViewController a delegate to BViewController and fill this protocol.
My question is, how does the B ViewController and the B ViewController Delegate connect? Is there a way in B's ViewController to tell that this action happened so that A knows that it happened?
source to share
There are many ways to do this, but the simplest is perhaps overriding viewWillAppear
in your TableViewController and placing the call there reloadData
.
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
tableView.reloadData()
}
viewWillAppear
is called every time the viewController is displayed on the screen, so whenever you go to your TableViewController it gets called and your objects will be reloaded.
source to share