uialertview - Swift3 UITextField in UIAlert validation after button pressed -


i have implemented alert window 2 text fields. , want perform validation: if 1 of text fields blank (user did not input value), application should not allow user press "done" button. don't want show alerts, want not allow user save blank data.

i have created function listed below. added 2 guards return. in case if user did not input anything, alert closes , nothing saved. don't want alert window closed.

how can done if can be? have not found answer. have checked this question, looks it's not applicable me. appreciate help!

private func addtable() {     let alert = uialertcontroller(title: nslocalizedstring("inputtableparams", comment: ""), message: nil, preferredstyle: .alert)     alert.addtextfield(configurationhandler: configuretablenametextfield)     alert.addtextfield(configurationhandler: configuretablecapacitytextfield)     alert.textfields?[0].autocapitalizationtype = .sentences     alert.textfields?[1].autocapitalizationtype = .sentences     alert.addaction(uialertaction(title: nslocalizedstring("alertcancel", comment: ""), style: .cancel, handler: nil))     alert.addaction(uialertaction(title: nslocalizedstring("alertdone", comment: ""), style: .default, handler: { (uialertaction) in         guard self.tablenametextfield.text != "" else {return}         guard self.tablecapacitytextfield.text != "" else {return}         let newtable = table(tablename: self.tablenametextfield.text!, tablecapacity: int(self.tablecapacitytextfield.text!)!)         let result = try? tablestable.getorcreatetable(table: newtable)         if result != nil {             self.updatetableview()         }     }))     self.present(alert, animated: true, completion: {}) } 

it looks not possible want, have implemented alert window error.

//mark: functions //functions alert window adding table private func configuretablenametextfield (textfield: uitextfield!) {     textfield.placeholder = nslocalizedstring("tablename", comment: "")     textfield.keyboardtype = .default     tablenametextfield = textfield } private func configuretablecapacitytextfield (textfield: uitextfield!) {     textfield.placeholder = nslocalizedstring("tablecapacity", comment: "")     textfield.keyboardtype = .numberpad     tablecapacitytextfield = textfield }  private func showalertparamsnotfilledproperly() {     let alertnocando = uialertcontroller(title: nslocalizedstring("alertnocando", comment: ""), message: nslocalizedstring("paramsnotfilledproperly", comment: ""), preferredstyle: .alert)     alertnocando.addaction(uialertaction(title: nslocalizedstring("alertdone", comment: ""), style: .cancel, handler: nil))     self.present(alertnocando, animated: true, completion: {}) }  private func showalertunabletosave() {     let alertnocando = uialertcontroller(title: nslocalizedstring("alertunabletosavedata", comment: ""), message: nslocalizedstring("checkinputparameters", comment: ""), preferredstyle: .alert)     alertnocando.addaction(uialertaction(title: nslocalizedstring("alertdone", comment: ""), style: .cancel, handler: nil))     self.present(alertnocando, animated: true, completion: {}) }  //functions managing tables private func addtable() {     let alert = uialertcontroller(title: nslocalizedstring("inputtableparams", comment: ""), message: nil, preferredstyle: .alert)     alert.addtextfield(configurationhandler: configuretablenametextfield)     alert.addtextfield(configurationhandler: configuretablecapacitytextfield)     alert.textfields?[0].autocapitalizationtype = .sentences     alert.textfields?[1].autocapitalizationtype = .sentences     alert.addaction(uialertaction(title: nslocalizedstring("alertcancel", comment: ""), style: .cancel, handler: nil))     alert.addaction(uialertaction(title: nslocalizedstring("alertdone", comment: ""), style: .default, handler: { (uialertaction) in         if self.tablenametextfield.text == "" || self.tablecapacitytextfield.text == "" {             self.showalertparamsnotfilledproperly()             return         }         if let number = numberformatter().number(from: self.tablecapacitytextfield.text!) {             let capacity = int(number)             let newtable = table(tablename: self.tablenametextfield.text!, tablecapacity: capacity)             let result = try? tablestable.getorcreatetable(table: newtable)             if result != nil {                 self.updatetableview()             }         } else {             self.showalertparamsnotfilledproperly()             return         }     }))     self.present(alert, animated: true, completion: {}) } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -