ios - Multiple UIAlertControllers to show one after the other in Swift -
i have set alertcontroller app, way works if section score higher 10, ui alert.
now problem if have 2 or 3 sections on 10, first uialert show, id see of them 1 after other (if sutuation happens
here code :
func sectionalert () { var message1 = nslocalizedstring("section 1 score ", comment: ""); message1 += "\(section1score)"; message1 += nslocalizedstring(" please review before continuing", comment: "1"); var message2 = nslocalizedstring("section 2 score ", comment: ""); message2 += "\(section2score)"; message2 += nslocalizedstring(" please review before continuing", comment: "2"); var message3 = nslocalizedstring("section 3 score ", comment: ""); message3 += "\(section3score)"; message3 += nslocalizedstring(" please review before continuing", comment: "3"); if (section1score >= 10){ let alertcontroller: uialertcontroller = uialertcontroller(title: nslocalizedstring("section 1 score on 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 on 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 on 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) } }
any ideas ??
thanks !
the primary problem you're using else if
. section 2 , 3 conditionals won't tested unless prior ones evaluate false
.
so want change this:
if (section1score >= 10){ // … } else if (section2score >= 10){ // … } else if (section3score >= 10){ // … }
to more this:
if (section1score >= 10){ // … } if (section2score >= 10){ // … } if (section3score >= 10){ // … }
that said, won't able present 3 view controllers @ same time. may want update code combine messages 1 alert. (this better user experience seeing 3 modal alerts appear @ same time.)
Comments
Post a Comment