ios - How can I add the name of a contact to my table view cell? -
hey have table view 5 cells , whenever 1 of them selected, abpeoplepickernavigationcontroller pops , user can select contact. how can make selected contact's name becomes text of cell's label? i've scoured internet 2 hours , can't figure out life of me. :( closest thing found used array store multiple contacts in dynamic cells have static cells... or hints appreciated. here's have far:
override func viewdidload() { super.viewdidload() } override func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { let picker = abpeoplepickernavigationcontroller() picker.peoplepickerdelegate = self presentviewcontroller(picker, animated: true, completion: nil) } func peoplepickernavigationcontroller(peoplepicker: abpeoplepickernavigationcontroller!, didselectperson person: abrecordref!, property: abpropertyid, identifier: abmultivalueidentifier) { let multivalue: abmultivalueref = abrecordcopyvalue(person, property).takeretainedvalue() let index = abmultivaluegetindexforidentifier(multivalue, identifier) let contactinfo = abmultivaluecopyvalueatindex(multivalue, index).takeretainedvalue() as! string let firstname = abrecordcopyvalue(person, kabpersonfirstnameproperty).takeretainedvalue() as! string } func peoplepickernavigationcontroller(peoplepicker: abpeoplepickernavigationcontroller!, shouldcontinueafterselectingperson person: abrecordref!, property: abpropertyid, identifier: abmultivalueidentifier) -> bool { peoplepickernavigationcontroller(peoplepicker, didselectperson: person, property: property, identifier: identifier) peoplepicker.dismissviewcontrolleranimated(true, completion: nil) return false; } func peoplepickernavigationcontrollerdidcancel(peoplepicker: abpeoplepickernavigationcontroller!) { peoplepicker.dismissviewcontrolleranimated(true, completion: nil) }
in didselectrowatindexpath
, create reference selected row.
override func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { // create property selected cell, , set when row selected self.selectedcell = tableview.cellforrowatindexpath(indexpath) let picker = abpeoplepickernavigationcontroller() picker.peoplepickerdelegate = self presentviewcontroller(picker, animated: true, completion: nil) }
when contact selected in abpeoplepickernavigationcontroller
, set text of selected cell firstname
.
func peoplepickernavigationcontroller(peoplepicker: abpeoplepickernavigationcontroller!, shouldcontinueafterselectingperson person: abrecordref!, property: abpropertyid, identifier: abmultivalueidentifier) -> bool { peoplepickernavigationcontroller(peoplepicker, didselectperson: person, property: property, identifier: identifier) let firstname = abrecordcopyvalue(person, kabpersonfirstnameproperty).takeretainedvalue() as! string // set text of selected cell self.selectedcell.textlabel.text = firstname // might have reload tableview data on completion reflect change peoplepicker.dismissviewcontrolleranimated(true, completion: { self.tableview.reloaddata() }) return false; }
also, believe shouldcontinueafterselectingperson:
has been deprecated since ios 8.0, should using didselectperson:
instead if targeting 8.0 , above.
apple docs reference.
Comments
Post a Comment