在我的應用程序中,我有一個視圖控制器,我以模態方式呈現。在這個視圖控制器我有一個表視圖。無論何時用戶在表格視圖中進行選擇,我都會關閉視圖控制器。關閉模式視圖控制器凍結了一段時間的應用程序,swift 3
問題是,即使調用dismiss函數,有時視圖控制器也不會被解散或在長時間延遲(5-7秒)後被解散。
這裏是我的代碼:
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")
}
}
任何幫助,高度讚賞。
編輯:
我使用解決了這個問題:
DispatchQueue.main.async
{
self.dismiss(animated: true) {
DDLogDebug("finished")
}
}
是否有這樣做沒有傷害?
尤金,你不應該在調度主塊中調用它,除非你是從後臺隊列中調用解僱(出於某種原因不明)嘗試在你的原始代碼中打印Thread.isMainThread,看看它說什麼 – Chris