uitableview - iOS Swift - TableView Delete Row Bug -


the error: 'invalid update: invalid number of rows in section 0. number of rows contained in existing section after update (1) must equal number of rows contained in section before update (1), plus or minus number of rows inserted or deleted section (0 inserted, 1 deleted) , plus or minus number of rows moved or out of section (0 moved in, 0 moved out).'

looking @ many related posts, still cannot find answer.

here relevant code snippets (does not contain of code):

var todoitems : [assignment] = [] var sections = dictionary<string, array<assignment>>() var sortedsections = [string]()  override func tableview(tableview: uitableview, commiteditingstyle editingstyle: uitableviewcelleditingstyle, forrowatindexpath indexpath: nsindexpath) {     if editingstyle == uitableviewcelleditingstyle.delete {         var tablesection = sections[sortedsections[indexpath.section]]         tablesection!.removeatindex(indexpath.row)         tableview.deleterowsatindexpaths([indexpath], withrowanimation: uitableviewrowanimation.automatic)     }  }   override func tableview(tableview: uitableview, titleforheaderinsection section: int) -> string? {     return sortedsections[section] }  override func viewdidload() {     super.viewdidload() }  override func didreceivememorywarning() {     super.didreceivememorywarning() }  override func numberofsectionsintableview(tableview: uitableview) -> int {     return sections.count }  override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {     return sections[sortedsections[section]]!.count } 

thanks help!

you deleted element in array update of dictionary sections missed :(

override func tableview(tableview: uitableview, commiteditingstyle editingstyle: uitableviewcelleditingstyle, forrowatindexpath indexpath: nsindexpath) {     if editingstyle == uitableviewcelleditingstyle.delete {         var tablesection = sections[sortedsections[indexpath.section]]         tablesection!.removeatindex(indexpath.row)          //add line         sections[sortedsections[indexpath.section]] = tablesection          tableview.deleterowsatindexpaths([indexpath], withrowanimation: uitableviewrowanimation.automatic) } 

}


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -