ios - Access UITextField's text content nested in a UITableView -
i'm trying access content of uitextfields that's nested in uitableview when "save" button pressed.
however, debugging (as shown further below) shows i can access texfield except text...
whatever type inside before pressing button has no impact...
i feel should use uitextfield delegate don't understand neither why nor how...
this code i'm using:
@ibaction func savenewguestbutton(sender: uibarbuttonitem) { let entity : nsentitydescription = nsentitydescription.entityforname("guest", inmanagedobjectcontext: self.managedobjectcontext)! // initialize record let record : guest = guest(entity:entity, insertintomanagedobjectcontext:managedobjectcontext) // populate record in 0..<3 { let indexpath : nsindexpath = nsindexpath(forrow: i, insection: 0) let cell = tableview(self.tableview, cellforrowatindexpath: indexpath) as! newguestprotocell if i==0 { record.guestfirst = cell.newguestfirstnametextfield.text println("indexpath :\(indexpath), recorded : \(record.guestfirst) , textfield : \(cell.newguestfirstnametextfield.text) + \(cell.newguestfirstnametextfield). test : \(cell.newguestfirstnametextfield.defaulttextattributes) , \(cell.newguestfirstnametextfield.attributedtext) , \(cell.newguestfirstnametextfield.placeholder) , \(cell.newguestfirstnametextfield.tag)") } if i==1 { record.guestlast = cell.newguestlastnametextfield.text println("indexpath :\(indexpath), recorded last : \(record.guestlast), recorded first : \(record.guestfirst) , textfield : \(cell.newguestlastnametextfield.text)") //newguest["lastname"] = cell.newguestlastnametextfield.text } if i==2 && guestimage != nil { record.guestimage = uiimagepngrepresentation(guestimage) nsdata println("indexpath :\(indexpath), recorded image: \(record.guestimage.superclass) , uiimageview's image : \(cell.guestimageiv.image)") } }
the console prints following, proves problems not in tableview, "for" loop access nor textfield (or it's "outlet") :
indexpath : {length = 2, path = 0 - 0}, recorded : and textfield : + >. test : [nsparagraphstyle: alignment 0, linespacing 0, paragraphspacing 0, paragraphspacingbefore 0, headindent 0, tailindent 0, firstlineheadindent 0, lineheight 0/0, lineheightmultiple 0, linebreakmode 4, tabs ( 28l, 56l, 84l, 112l, 140l, 168l, 196l, 224l, 252l, 280l, 308l, 336l ), defaulttabinterval 0, blocks (null), lists (null), basewritingdirection -1, hyphenationfactor 0, tighteningfactor 0, headerlevel 0, nsshadow: nsshadow {0, -1} color = {(null)}, nsfont: font-family: ".helveticaneueinterface-regular"; font-weight: normal; font-style: normal; font-size: 14.00pt, nscolor: uidevicergbcolorspace 0 0 0 1] , optional() , optional("first name") , 0 indexpath : {length = 2, path = 0 - 1}, recorded last : , recorded first : , textfield : indexpath : {length = 2, path = 0 - 2}, recorded image: optional(nsmutabledata) , uiimageview's image : optional( size {1500, 1001} orientation 0 scale 1.000000)
by reading code, doing things wrong:
let cell = tableview(self.tableview, cellforrowatindexpath: indexpath) as! newguestprotocell
the cellforrowatindexpath used prepare view show it. should clear typed in, , fill in content correct record. (the record @ indexpath). should view textview's text null.
regard on how values out, can setup delegate uitextfielddelegate in exact method. tableview(self.tableview, cellforrowatindexpath: indexpath).
Comments
Post a Comment