In my app I have a view controller, that I present modally. In this view controller I have a table view. Whenever user makes a selection in a table view, I dismiss the view controller.
The problem is that sometimes the view controller is not getting dismissed or getting dismissed after a long delay (5-7 seconds) even though the dismiss function is called.
Here is my code:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
if tableView == self.quarterTableView
{
self.delegate?.modalViewController(modalVC: self, dismissedWithValue:self.quarterPeriods[indexPath.row])
}
else if tableView == self.monthTableView
{
self.delegate?.modalViewController(modalVC: self, dismissedWithValue: self.monthPeriods[indexPath.row])
}
Print("didSelectRowAt dismiss")
self.dismiss(animated: true) {
Print("finished")
}
}
Any help is highly appreciated.
EDIT:
I resolved the issue by using:
DispatchQueue.main.async
{
self.dismiss(animated: true) {
DDLogDebug("finished")
}
}
Is there any harm done by doing so?
if you want something on the UI to happen right away, execute it on the main queue
DispatchQueue.main.async(execute: {
self.dismiss(animated: true) {
Print("finished")
})
try to use a dispatch DispatchQueue
DispatchQueue.main.async(execute: {
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With