您好,我是一个新手iOS应用程序开发者。
我已经使用了一些cocoapods框架来制作警报视图。
我使用的是下面提到的SweetAlert警报视图。
我尝试在不按警报中的选项按钮的情况下编程方式解除警报。
请有人帮忙解决这个问题。
您好,我是一个新手iOS应用程序开发者。
我已经使用了一些cocoapods框架来制作警报视图。
我使用的是下面提到的SweetAlert警报视图。
我尝试在不按警报中的选项按钮的情况下编程方式解除警报。
请有人帮忙解决这个问题。
dismissViewControllerAnimated
方法来关闭警告框。alertControllerObject?.dismissViewControllerAnimated(true, completion: nil)
pressed(sender: UIButton!)
方法。@IBAction func aBasicMessageAlert(sender: AnyObject) {
let sweetAlert = SweetAlert().showAlert("Here's a message!")
close(sweetAlert, after: 2.0)
}
func close(alert: SweetAlert, after seconds: Double) {
NSTimer.scheduledTimerWithTimeInterval(seconds,
target: self,
selector: #selector(closeAlert),
userInfo: ["alert": alert],
repeats: true)
}
func closeAlert(timer: NSTimer) {
let alert = timer.userInfo!["alert"] as! SweetAlert
let dummyCloseButton = UIButton()
dummyCloseButton.tag = 0
alert.pressed(dummyCloseButton)
}
yourAlerView.dismiss(withClickedButtonIndex: 0, animated: true)
当你处理回车键时,ButtonIndex是你想要默认点击以隐藏警报的按钮索引。
希望这能帮到你。
你需要在SweetAlert中添加此方法,并调用它。
func closeAlert(){
UIView.animateWithDuration(0.5, delay: 0.0, options: UIViewAnimationOptions.CurveEaseOut, animations: { () -> Void in
self.view.alpha = 0.0
}) { (Bool) -> Void in
self.view.removeFromSuperview()
self.cleanUpAlert()
//Releasing strong refrence of itself.
self.strongSelf = nil
}
}
实现类似这样的警告
let alert = SweetAlert() // take this as global
func showAlert(){
alert.showAlert(title as String, subTitle: msg as String, style: style, buttonTitle:buttonOtherTitle as String, buttonColor:UIColor.redColor() , otherButtonTitle: buttonOkTitle as String, otherButtonColor: colors.KBlueTextColor!) { (isOtherButton) -> Void in
if isOtherButton
{
completionHandler(false)
}
else
{
completionHandler(true)
}
}
}
func CloseAlert(){
alert.closeAlert()
}
试一下这个
当你调用Alert方法时也叫这个名字,在alert方法内部
NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: "hideAlert:", userInfo: userInfo, repeats: true) //repeats: false
在 Alert 方法之外调用 This
func hideAlert(){
isOtherButton == true// isOtherButton getting from your SweetAlert Demo
}