ios - Blocking a Loop Using UIAlertController -
is there way block loop?
i have loop inside it, ask user dialog box. pause loop after user press ok or cancel.
is possible?
because looping alertcontroller looks ugly especialy when have many loops.
for request in friendrequests { let alertcontroller = uialertcontroller(title: "friend request", message: "would accept friend request?", preferredstyle: uialertcontrollerstyle.alert); let cancelaction: uialertaction = uialertaction(title: "ok", style: uialertactionstyle.cancel, handler: nil); let confirmaction: uialertaction = uialertaction(title: "ok", style: uialertactionstyle.default, handler: nil); alertcontroller.addaction(cancelaction); alertcontroller.addaction(confirmaction); //how block or wait until user press button?? self.navigationcontroller.presentviewcontroller(alertcontroller); } any thoughts?
use recursive function rather loop
example
var name:[string] = ["abcd","efgh","ijkl","mnop","qrst","uvwx"] self.friendreuqest(name, index: 0) func friendreuqest(name:[string],index:int) { if index < name.count { let alertcontroller = uialertcontroller(title: name[index], message: "would accept friend request?", preferredstyle: uialertcontrollerstyle.alert) let cancelaction: uialertaction = uialertaction(title: "dismiss", style: uialertactionstyle.cancel){ (action: uialertaction!) -> void in // stuff here when press cancel } let confirmaction: uialertaction = uialertaction(title: "add", style: uialertactionstyle.default) { (action: uialertaction!) -> void in self.friendreuqest(name, index: (index + 1)) } alertcontroller.addaction(cancelaction) alertcontroller.addaction(confirmaction) self.presentviewcontroller(alertcontroller, animated: true, completion: nil) } }
Comments
Post a Comment