【发布时间】:2017-05-24 12:56:02
【问题描述】:
我正在开发简单的倒数计时器(Swift)。当时间达到“0”时,我想显示 alertView。为此,我正在使用 JSSAlertView 吊舱。
一切正常,但使用那个 alertView 我也得到了这个:警告:尝试展示已经展示的内容
我该如何解决?
我不使用 Storyboard 或 Xib 文件。一切都是以编程方式编写的。
我尝试了使用 Google 找到的不同解决方案 - 对我没有任何帮助。
附: 我在下面附上了我的代码。我有两个 ViewController:
第一个 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 但stackoverflow.com/questions/36450931/… 可能会有所帮助
-
谢谢 Mike Alter,但它有点不同......我的朋友刚刚帮我解决了这个问题。
标签: ios mobile uiviewcontroller swift3 cocoapods