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

标签 ios swift xcode uialertview uialertaction

最初,我显示一个警报,当单击"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/

相关文章:

ios - 为什么这样的代码可以编译通过呢?在iOS UIViewController中调用popToRootViewControllerAnimated?

ios - 调用 touchesBegan 时动画 UIView 对象跳转

xcode - 根据标签大小更改 UICollectionView 单元格大小

ios - 如何设置 UNNotificationRequest 自定义重复间隔?

ios - 关闭模态视图 Controller 后 TableView 数据加载多次

xcode - 在 SQLite.swift 的过滤器中使用变量

iphone - objective-c 中的内存问题

ios - IOS8.0 UISearchController使用方法

ios - 从 NSMutableArray 错误中删除值

ios - Sprite Kit 创建倒数计时器问题