最初,当单击“是”将显示第二个警报时,我将首先显示一个警报;在第二个警报中,当用户按下“重置”时,我希望显示进度视图,而该进度视图中的调用服务并不仅显示正在发生的服务调用--我也想显示进度视图,那么如何在第二个警报中按“确定”之后显示进度视图呢?
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)
}
}
调用服务可能很快,您无法看到进度验证DispatchQueue.main.asyncAfter
Utility.showGlobalProgressHUD(withTitle: "Loading...")
HTTPRequest.serviceReq(newPin: "129354") { (ResetModel) in
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
Utility.dismissGlobalHUDInMainThread()
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。