ios - Update CoreData Object -
i'd update coredata object. backgrund: made app includes uitableview. in textlabel of uitableviewcell name. in detailtextlabel of cell date can changed/updated. i'd change date.
i wrote following code:
var people = [nsmanagedobject]() func savedate(date: nsdate) { //1 let appdelegate = uiapplication.sharedapplication().delegate appdelegate let managedcontext = appdelegate.managedobjectcontext! //2 let entity = nsentitydescription.entityforname("person", inmanagedobjectcontext:managedcontext) let person = people[dateindexpath.row] //3 person.setvalue(date, forkey: "datum") //4 var error: nserror? if !managedcontext.save(&error) { println("could not save \(error), \(error?.userinfo)") } //5 people.append(person) tableview.reloaddata() }
now, if run code: date updated cell in date has been updated displayed 2 times. example if added 3 cells , changed date in 3rd cell, 4 cells displayed , 2 of them have same content/are duplicated.
does knows how solve problem?
you're adding additional object array each time. updated person
in array , display new information when reload table data. fix this, take out line:
people.append(person)
Comments
Post a Comment