Swift 警报自定义显示和分发
Swift alert custom show and dispense
我在 viewcontroller 中创建了一个自定义警报,遵循该问题投票最多的答案的准则:
我用它来显示警报,它用作 "loading"。
let pending = UIAlertController()
override func viewDidLoad() {
super.viewDidLoad()
[…]
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let pending = storyboard.instantiateViewControllerWithIdentifier("alertaLoad")
pending.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
pending.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve
[…]
}
显示:
self.presentViewController(self.pending, animated: true, completion: nil)
我成功地展示了它,但我需要通过在我的过程结束后调用它的 viewcontroller 来终止它,而不是像我引用的示例中那样由它自己终止。
我试过了,但没有任何反应。
self.pending.dismissViewControllerAnimated(false, completion: { (vetor) -> Void in
[…]
})
我怎样才能正确地做到这一点?
在演示 UIViewController
上调用 dismiss
,而不是在演示中调用:
self.dismiss(animated: true) {
// go on
}
我在 viewcontroller 中创建了一个自定义警报,遵循该问题投票最多的答案的准则:
我用它来显示警报,它用作 "loading"。
let pending = UIAlertController()
override func viewDidLoad() {
super.viewDidLoad()
[…]
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let pending = storyboard.instantiateViewControllerWithIdentifier("alertaLoad")
pending.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
pending.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve
[…]
}
显示:
self.presentViewController(self.pending, animated: true, completion: nil)
我成功地展示了它,但我需要通过在我的过程结束后调用它的 viewcontroller 来终止它,而不是像我引用的示例中那样由它自己终止。 我试过了,但没有任何反应。
self.pending.dismissViewControllerAnimated(false, completion: { (vetor) -> Void in
[…]
})
我怎样才能正确地做到这一点?
在演示 UIViewController
上调用 dismiss
,而不是在演示中调用:
self.dismiss(animated: true) {
// go on
}