从第二个警报视图按“确定”时,进度 hud 未显示
Posted
技术标签:
【中文标题】从第二个警报视图按“确定”时,进度 hud 未显示【英文标题】:Progress hud is not showing when press ok from second alert view 【发布时间】:2019-12-19 12:01:20 【问题描述】:最初我在单击“是”时显示一个警报,它将显示第二个警报,当用户按下重置时,在第二个警报中我想显示进度视图,并且在此进度视图中调用服务不显示仅发生服务调用我想还显示进度视图,那么如何在第二个警报中按确定后显示进度视图?
func makeServiceCall()
Utility.showGlobalProgressHUD(withTitle: "Loading...")
HTTPRequest.serviceReq(newPin: "129354") (ResetModel) in
Utility.dismissGlobalHUDInMainThread()
Utility.showAlertMessageInMainThread(title: " Reset", msg: "Your request to reset has been successfully completed.")
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
Utility.confirmationActionSheetMsg(title: "First Alert", msg: "alertMsg", okActionTitle: "Yes", cancelActionTitle: "Cancel", success:
Utility.showAlertViewWithTextField(title: "Second Alert", msg: "alertMsg", okActionTitle: "Reset", cancelActionTitle: "Cancel", success:
self.makeServiceCall()
, cancel:
print("Canceled by user")
)
)
print("cancel")
实用程序文件是 -
class Utility
static func showGlobalProgressHUD(withTitle title: String?) -> MBProgressHUD?
let window: UIWindow? = UIApplication.shared.windows.last
let hud = MBProgressHUD.showAdded(to: window, animated: true)
hud?.labelText = title
hud?.dimBackground = true
hud?.cornerRadius = 7
hud?.margin = 30
hud?.detailsLabelFont = UIFont.boldSystemFont(ofSize: 15)
window?.isUserInteractionEnabled = true
hud?.isUserInteractionEnabled = true;
return hud
static func confirmationActionSheetMsg(title: String, msg: String, okActionTitle:String, cancelActionTitle:String, success: (() -> Void)? , cancel: (() -> Void)?)
let alert = UIAlertController(title: title, message: msg, preferredStyle: UIAlertController.Style.actionSheet)
let successAction: UIAlertAction = UIAlertAction(title: okActionTitle, style: .destructive)
action -> Void in
success?()
let cancelAction: UIAlertAction = UIAlertAction(title: cancelActionTitle, style: .cancel)
action -> Void in
cancel?()
alert.addAction(successAction)
alert.addAction(cancelAction)
UIApplication.shared.keyWindow?.rootViewController?.present(alert, animated: true, completion: nil)
static func showAlertViewWithTextField(title: String, msg: String, okActionTitle:String, cancelActionTitle:String, success: (() -> Void)? , cancel: (() -> Void)?)
let alert = UIAlertController(title: title, message: msg, preferredStyle: UIAlertController.Style.alert)
alert.addTextField (textField) in
textField.placeholder = "Enter new pin."
alert.addTextField (textField) in
textField.placeholder = "Confirm new pin."
let successAction: UIAlertAction = UIAlertAction(title: okActionTitle, style: .destructive)
action -> Void in
let textOfFirstTextfield = alert.textFields?[0].text
print(textOfFirstTextfield)
success?()
let cancelAction: UIAlertAction = UIAlertAction(title: cancelActionTitle, style: .cancel)
action -> Void in
cancel?()
alert.addAction(successAction)
alert.addAction(cancelAction)
UIApplication.shared.keyWindow?.rootViewController?.present(alert, animated: true, completion: nil)
【问题讨论】:
请同时显示showGlobalProgressHUD
添加了 showGlobalProgressHUD
当我在显示 hud 时延迟而不是在关闭 hud 时延迟时,它起作用了。谢谢!
【参考方案1】:
当我在显示 hud 时延迟而不是在关闭 hud 时延迟时,它起作用了
func makeServiceCall()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1)
Utility.showGlobalProgressHUD(withTitle: "Loading...")
HTTPRequest.serviceReq(newPin: "129354") (ResetModel) in
Utility.dismissGlobalHUDInMainThread()
Utility.showAlertMessageInMainThread(title: " Reset", msg: "Your request to reset has been successfully completed.")
【讨论】:
以上是关于从第二个警报视图按“确定”时,进度 hud 未显示的主要内容,如果未能解决你的问题,请参考以下文章
Swift 5. 从第二个表格视图单元格(第二个 indexpath.row )显示数组
仅当从警报调用时,如何向第二个向下钻取View Controller添加按钮?