我正在简单的倒数计时器(斯威夫特)。当时间到达“0”时,我想显示alertView。为此,我使用JSSAlertView窗格。尝试呈现<JSSAlertView.JSSAlertView ...它已经呈现
一切运作良好,但与alertView我也得到这个:警告:试图提出在已经呈现
我怎样才能解决这个问题?
我不使用Storyboard或Xib文件。一切都以编程方式编写。
我v'e尝试使用谷歌发现不同的解决方案 - 没有为我工作。
P.S. 我附上了我的代码。我有两个ViewControllers:
第一的viewController有启动按钮:
class FirstViewController: UIViewController {
func startButtonCLicked(_ button: UIButton) {
let controller = SecondViewController()
present(controller, animated: true)
}
}
二的viewController具有定时功能和alertView:
class SecondViewController: UIViewController {
func updateTimer() {
if seconds > 0 {
print(seconds)
seconds -= 1
timerLabel.text = String(Timer.timeFormatted(seconds))
} else {
let alertview = JSSAlertView().show(self,
title: "Hey",
text: "Hey",
buttonText: "Hey",
color: UIColorFromHex(appColor.hexMainOrangeColor, alpha: 1))
alertview.setTextTheme(.light)
}
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if timer.isValid == false {
timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(SecondViewController.updateTimer) , userInfo: nil, repeats: true)
}
}
}
干杯!
不知道与JSAlertview但http://stackoverflow.com/questions/36450931/countdown-in-uialertcontroller可能会帮助 –
谢谢麦克阿尔特,但它有点不同...我的朋友刚刚帮我解决这个问题。 – Jonagold