【发布时间】:2021-11-26 04:53:16
【问题描述】:
在弹出页面中,我试图将一些数据存储在 CoreData 中,我需要显示加载视图,直到该过程完成。
我找到了一种简单易用的方法,使用警报控制器显示加载标签。在函数中,我添加了一个 shouldPresent 布尔值,以在 coreData 进程完成时使其为 false 并隐藏警报。
private func presentLoadingView(shouldPresent: Bool) {
let alert = UIAlertController(title: nil, message: "Retrieving Owner Data", preferredStyle: .alert)
let loadingIndicator = UIActivityIndicatorView(frame: CGRect(x: 3, y: 5, width: 50, height: 50))
loadingIndicator.hidesWhenStopped = true
loadingIndicator.style = UIActivityIndicatorView.Style.medium
loadingIndicator.startAnimating()
alert.view.addSubview(loadingIndicator)
presentAnimated(alert)
if !shouldPresent {
alert.dismiss(animated: true)
}
}
问题是,当我使用
dismiss(animated: true)
当我使用时,整个弹出框将被关闭
alert.dismiss(animated: true)
什么也没发生,谁能帮我解决这个问题。提前致谢。
【问题讨论】:
-
从 presentLoadingView 中取出“让警报”。并调用 alert.dismiss(animated: true, completion: nil)
标签: swift uialertviewcontroller