ios - Cant dismiss my previous alertcontroller completely -
i trying use 1 single alert controller include multiple alert showing functions , 1 dismiss function.but having this warning in console , other alert don't show.i wonder why?and solution that.
here alert controller
import uikit class myalertviewcontroller: uiviewcontroller { var myalertcontroller : uialertcontroller! override func viewdidload() { super.viewdidload() } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } func displayloadingalert(viewcontroller: uiviewcontroller?) -> uialertcontroller { var controllertopresent = viewcontroller if controllertopresent == nil { controllertopresent = self } //create alert controller myalertcontroller = uialertcontroller(title: "loading...", message: “we receiving data,please wait“, preferredstyle: .actionsheet) controllertopresent!.presentviewcontroller(myalertcontroller, animated: true, completion: nil) return myalertcontroller } func connectionerroralert(viewcontroller: uiviewcontroller?) -> uialertcontroller { var controllertopresent = viewcontroller if controllertopresent == nil { controllertopresent = self } //create alert controller myalertcontroller = uialertcontroller(title: "not connected", message: “no internet connection”, preferredstyle: .alert) let defaultaction = uialertaction(title: "ok", style: .default,handler:nil) myalertcontroller.addaction(defaultaction) controllertopresent!.presentviewcontroller(myalertcontroller, animated: true, completion: nil) return myalertcontroller } func requesttimeouterroralert(viewcontroller: uiviewcontroller?) -> uialertcontroller { var controllertopresent = viewcontroller if controllertopresent == nil { controllertopresent = self } //create alert controller myalertcontroller = uialertcontroller(title: "request time out", message: “please click retry”, preferredstyle: .alert) let defaultaction = uialertaction(title: "ok", style: .default,handler:nil) myalertcontroller.addaction(defaultaction) controllertopresent!.presentviewcontroller(myalertcontroller, animated: true, completion: nil) return myalertcontroller } func dismissloadingalert(){ myalertcontroller.dismissviewcontrolleranimated(true, completion: nil) } } i use dismissloadingalert() when results api.but,when don't results api.i used delegate method protocol.
func didnotreceiveapiresults(results: bool,error:nserror){ dispatch_async(dispatch_get_main_queue(), { // condition enter if dont results , show user alert. if (results) { // have done dismiss first data receiving alert,what doing wrong? self.myalertcontroller.dismissloadingalert() if error.localizeddescription == "the internet connection appears offline."{ self.myalertcontroller.connectionerroralert(self) self.cartableview.hidden=true self.retrybutton?.hidden=false self.retrybutton?.enabled=true } if error.localizeddescription == "request time out."{ self.myalertcontroller.requesttimeouterroralert(self) self.cartableview.hidden=true self.retrybutton?.hidden=false self.retrybutton?.enabled=true } }else{ self.myalertcontroller.displayloadingalert(self) self.retrybutton?.hidden=true self.retrybutton?.enabled=false self.cartableview.hidden=false self.cartableview.reloaddata() } }) }
you on wrong track. should not subclass controller.
the uialertcontroller class intended used as-is , not support subclassing. view hierarchy class private , must not modified.
if need convenience class, refactor using nsobject subclass presents dynamic uialertcontroller instances.
Comments
Post a Comment