我已經爲我的應用程序設置了一個alertcontroller,它的工作方式是如果部分得分高於10,你會得到一個UI警報。多個UIAlertControllers在Swift中一個接一個地顯示
我現在的問題是,如果我有2個或3個部分超過10,我只得到了第一個UIalert顯示,ID喜歡看所有的人一前一後(如果這sutuation發生
這裏我的代碼:。
func SectionAlert() {
var message1 = NSLocalizedString("Section 1 score is now ", comment: "");
message1 += "\(section1score)";
message1 += NSLocalizedString(" please review before continuing", comment: "1");
var message2 = NSLocalizedString("Section 2 score is now ", comment: "");
message2 += "\(section2score)";
message2 += NSLocalizedString(" please review before continuing", comment: "2");
var message3 = NSLocalizedString("Section 3 score is now ", comment: "");
message3 += "\(section3score)";
message3 += NSLocalizedString(" please review before continuing", comment: "3");
if (section1score >= 10){
let alertController: UIAlertController = UIAlertController(title: NSLocalizedString("Section 1 score is over 10", comment: ""),
message: " \(message1)",
preferredStyle: .Alert)
let OKAction = UIAlertAction(title: "OK", style: .Default) {
action -> Void in }
alertController.addAction(OKAction)
self.presentViewController(alertController, animated: true, completion: nil)
} else if (section2score >= 10){
let alertController: UIAlertController = UIAlertController(title: NSLocalizedString("Section 2 Score is over 10", comment: ""),
message: "\(message2)",
preferredStyle: .Alert)
let OKAction = UIAlertAction(title: "OK", style: .Default) {
action -> Void in }
alertController.addAction(OKAction)
self.presentViewController(alertController, animated: true, completion: nil)
} else if (section3score >= 10){
let alertController: UIAlertController = UIAlertController(title: NSLocalizedString("Section 3 Score is over 10", comment: ""),
message: "\(message3)",
preferredStyle: .Alert)
let OKAction = UIAlertAction(title: "OK", style: .Default) {
action -> Void in }
alertController.addAction(OKAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
}
任何想法?
感謝
嗯,我想獲得連續3個警告,如果需要的是有,就是要與如果只發生?因爲我試過這樣並沒有得到好的結果 – Jp4Real
如果你願意,你可以這樣做,但你需要適當的時間視圖控制器演示。你不能一次呈現全部。 –
(有關更多討論,請參閱[連續UIAlertControllers](http://stackoverflow.com/q/25932589/1445366);這不像UIAlertView那樣支持開箱即用。) –