我试图在一段时间后显示 UIAlertView(比如在应用程序中做某事后 5 分钟)。如果应用程序已关闭或在后台,我已经通知用户。但我想在应用程序运行时显示 UIAlertView。我不想一次又一次地刷新。三分钟后,我必须显示一些警报,例如您是否要保存?
1143 次
4 回答
1
利用
self.perform(#selector(displayAlert), with: nil, afterDelay: 300)
其中 display alert 是显示警报的函数。
于 2016-11-02T10:48:38.687 回答
0
我认为具有自定义延迟的 UIAlertView 有另一种最佳方法是您可以随时使用 timeInterval 安排本地通知。
于 2016-11-02T11:49:12.770 回答
0
最后,我找到了问题的答案:我正在使用带有以下代码的点击手势:
func displayAlert()
{
let alert = UIAlertController(title: "My Title", message: "This is my message.", preferredStyle: UIAlertControllerStyle.alert)
// add an action (button)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
// show the alert
self.present(alert, animated: true, completion: nil)
self.timer = NSTimer.scheduledTimerWithTimeInterval(50.0, target: self, selector: #selector(SONGS.displayAlert), userInfo: nil, repeats: false)
timer.invalidate()// stop the timer
}
如果你设置repeats:true,如果你想停止计时器,它会每50秒显示一次警报,你可以在任何你想要的地方使用timer.invalidate()。谢谢
于 2016-11-03T14:13:14.617 回答
0
它对我有用:
self.timer = NSTimer.scheduledTimerWithTimeInterval(10.0, target: self, selector: #selector(SONGS.displayAlert), userInfo: nil, repeats: false)
func displayAlert()
{
self.message.dismissWithClickedButtonIndex(0,animated: true)
}
于 2016-11-18T10:23:50.827 回答