ios - UIAlertController accepts text input, set cell label to text input -


i trying have uialertcontroller accept text user , set user's input label of first cell of table view.

var objects = [anyobject]()  func insertnewobject(sender: anyobject) {      var alert = uialertcontroller(title: "new routine", message: "", preferredstyle: uialertcontrollerstyle.alert)     var inputtextfield: uitextfield?      alert.addtextfieldwithconfigurationhandler({(textfield: uitextfield!) in         textfield.placeholder = "routine name"         inputtextfield = textfield     })     alert.addaction(uialertaction(title: "add", style: uialertactionstyle.default, handler: { (action) -> void in         self.objects.insert(inputtextfield!, atindex: 0)         let indexpath = nsindexpath(forrow: 0, insection: 0)         self.tableview.insertrowsatindexpaths([indexpath], withrowanimation: .automatic)         }))     alert.addaction(uialertaction(title: "cancel", style: uialertactionstyle.default, handler: nil))      self.presentviewcontroller(alert, animated: true, completion: nil) } 

unfortunately, sets cell label <_uialertcontrollertextfield:...

i guessing in action of "add" button have "inputtextfield". unsure of how correctly capture text submitted user.

you adding text field array when should adding contents.

instead of:

self.objects.insert(inputtextfield!, atindex: 0) 

do this:

self.objects.insert(inputtextfield.text!, atindex: 0) 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -