从第二个警报视图中按ok时未显示进度显示

问题描述 投票:3回答:1

最初,我是在单击“是”时显示一个警报,它将显示第二个警报,在第二个警报中,当用户按下“重置”时,我想显示进度视图,并且此进度视图中的呼叫服务未显示正在发生的服务呼叫,我想显示进度视图也是如此,那么在第二次警报中按“确定”后如何显示进度视图?

      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)

        }


    }
ios swift xcode uialertview uialertaction
1个回答
0
投票

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

            }
}
        }
© www.soinside.com 2019 - 2024. All rights reserved.