gpt4 book ai didi

ios - 从第二个警报 View 中按“确定”时,进度平视显示器不显示

转载 作者:行者123 更新时间:2023-12-03 01:59:18 25 4
gpt4 key购买 nike

最初,我显示一个警报,当单击"is"时,它将显示第二个警报,在第二个警报中,当用户按下重置时,我想显示进度 View ,并且此进度 View 中的调用服务不显示仅发生服务调用,我想还显示进度 View ,那么在第二个警报中按“确定”后如何显示进度 View ?

      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)

}


}

最佳答案

当我在显示 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.")

}
}
}

关于ios - 从第二个警报 View 中按“确定”时,进度平视显示器不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59409388/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com