开发者社区> 问答> 正文

在第二个警报视图中按确定时,未显示进度HUD

最初,当单击“是”将显示第二个警报时,我将首先显示一个警报;在第二个警报中,当用户按下“重置”时,我希望显示进度视图,而该进度视图中的调用服务并不仅显示正在发生的服务调用--我也想显示进度视图,那么如何在第二个警报中按“确定”之后显示进度视图呢?

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)

        }


    }

展开
收起
游客5akardh5cojhg 2019-12-19 21:03:03 696 0
1 条回答
写回答
取消 提交回答
  • 调用服务可能很快,您无法看到进度验证DispatchQueue.main.asyncAfter

    Utility.showGlobalProgressHUD(withTitle: "Loading...")
          HTTPRequest.serviceReq(newPin: "129354") { (ResetModel) in
              DispatchQueue.main.asyncAfter(deadline: .now() + 3) { 
                 Utility.dismissGlobalHUDInMainThread()
              }
    
    2019-12-19 21:03:28
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载