2016-04-06 16 views
0

アラートコントローラで3秒間カウントダウンします。これを行う方法がわかりません。私は3秒以内に消えてアラートを得ることができます、ちょうどカウントダウンがありません。UIAlertControllerのカウントダウン

//simple alert dialog 
let alertController = UIAlertController(title: "Workflow successful", message: "Modified reminder's priority or list.", preferredStyle: .Alert) 

var secs = 3 
let defaultAction = UIAlertAction(title: "Dismiss in " + secs, style: .Default, handler: nil) 
alertController.addAction(defaultAction) 

dispatch_async(dispatch_get_main_queue()) { 
    //self.presentViewController(alertController, animated: true, completion: nil) 
    self.showViewController(alertController, sender: self) 
} 

let delayTime = dispatch_time(DISPATCH_TIME_NOW, 
       Int64(secs * Double(NSEC_PER_SEC))) 
dispatch_after(delayTime, dispatch_get_main_queue()) { 
    alertController.dismissViewControllerAnimated(true, completion: nil) 
} 

答えて

1

あなたのビューコントローラを却下する遅延時間を設定した後、2番目の後などの機能を呼び出すためのタイマーを設定することができます

var timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(self.decrease), userInfo: nil, repeats: true) 

func decrease() 
{ 
    self.secs-=1 
    self.defaultAction.setValue("Dismiss in \(self.secs)", forKey: "title") 
} 

そして、それはあなたの新しい時間とタイトルを更新します。

関連する問題