在我的应用程序中,我有一个视图控制器,我以模态的方式呈现它。在这个视图控制器中,我有一个表视图。每当用户在表视图中进行选择时,我都会关闭视图控制器。
问题是,有时视图控制器不会被取消,或者在很长一段时间(5-7秒)后被取消,即使调用了dismiss函数。
下面是我的代码:
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")
}
}这样做有什么害处吗?
发布于 2017-01-19 01:47:13
如果您希望UI上的某些内容立即发生,请在主队列上执行它
DispatchQueue.main.async(execute: {
self.dismiss(animated: true) {
Print("finished")
})发布于 2017-01-19 01:46:31
尝试使用调度DispatchQueue
DispatchQueue.main.async(execute: {
})发布于 2017-01-19 02:36:50
没什么坏处。你只需要让主线程同时完成两个任务。
https://stackoverflow.com/questions/41726017
复制相似问题