ios - Deleting UITableViewCell: NSInternalInconsistencyException? -


i'm getting error when try delete cell uitableview. i've looked @ numerous links (this 1 example i'm going off of. below code:

var countdowntime = expirdate - currentdate     timer.setcountdowntime(countdowntime)     println("count : \(self.offers.count)")     timer.startwithendingblock { (countdowntime) -> void in         //if times have expired, delete row         self.tableview.beginupdates()         self.offers.removeatindex(indexpath.row)         self.tableview.deleterowsatindexpaths([indexpath.row], withrowanimation: uitableviewrowanimation.fade)         self.tableview.endupdates()     } timer.start()  func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {     return offers.count } //only 1 section func numberofsectionsintableview(tableview: uitableview) -> int {     return 1 } 

i want remove cell when timer has completed , offers array array use populate uitableview. going off of assertion failure -[uitableview _endcellanimationswithcontext] thought me delete/insert rows correctly still error saying:

*** terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: '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 (1 inserted, 0 deleted) , plus or minus number of rows moved or out of section (0 moved in, 0 moved out).'

any appreciated!

edit: issue might having trying delete cell while inserting cell uitableview. inserting cell, setting cell contents, deleting cell if timer cell has existed on 24 hours. bad because cell try insert next cell when thinks there 1 cell in table view. there better ways this?

edit 2: code inserting table:

           ...//code insert database     override func viewdidload() {     super.viewdidload()      //setupoffers()      setupoffers { (result, offer) -> void in         if(result == true){             //insert each row 1 one.             var currentcount = self.offers.count             var indexpaths: [nsindexpath] = [nsindexpath]()             indexpaths.append(nsindexpath(forrow:currentcount, insection: 0))             self.offers.append(offer)             currentcount++;              //update based on each table view index.             self.tableview.beginupdates()             self.tableview.insertrowsatindexpaths(indexpaths, withrowanimation: uitableviewrowanimation.bottom)             self.tableview.endupdates()             //method 2 update uitableview              //self.tableview.reloaddata()         }     }     // additional setup after loading view, typically nib.     self.tableview.delegate = self     self.tableview.datasource = self     self.tableview.rowheight = uitableviewautomaticdimension     self.tableview.rowheight = 145.0  } 

add statement self.offers.removeatindex(indexpath.row) before starting updates on table view self.tableview.beginupdates() as

self.offers.removeatindex(indexpath.row) self.tableview.beginupdates() 

as happen start update on table view , number of rows returned before deleting object array, , result in inconsistency.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -