I have a table view with two xibs for custom cells.
The first xib contains only uilabel, and the second only uibutton.
After clicking the button, a uibutton is added someTagsArray(the array that I use to count in the numberOfRows function) and new lines should be inserted, but instead I get this nasty error
Invalid update: invalid number of lines in section 0. The number of lines contained in an existing section after update (8) must be equal to the number of lines contained in this section before update (4), plus or minus the number of lines inserted or deleted from this section (0 inserted, 0 deleted) and plus or minus the number of rows moved to or from this section (0 moved, 0 displayed).
Here is my code (numberOfRowsInSection)
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) ->
Int {
return someTagsArray.count + 1
}
cellForRowAtIndexPath
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if(indexPath.row < someTagsArray.count){
var cell:TblCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! TblCell
cell.lblCarName.text = linesmain["start"]![indexPath.row]
return cell
} else {
var celle:vwAnswers = self.tableView.dequeueReusableCellWithIdentifier("cell2") as! vwAnswers
celle.Answer1.setTitle(answersmain["start"]![0], forState:UIControlState.Normal)
answertitle1 = "\(celle.Answer1.currentTitle!)"
return celle
}}
and finally, the function code that the application breaks
func insertData(){
someTagsArray += linesmain[answertitle1]!
tableView.beginUpdates()
let insertedIndexPathRange = 0..<self.linesmain[answertitle2]!.count-4
var insertedIndexPaths = insertedIndexPathRange.map { NSIndexPath(forRow: $0, inSection: 0) }
tableView.insertRowsAtIndexPaths(insertedIndexPaths, withRowAnimation: .Fade)
tableView.endUpdates()
}
Thanks guys.
source
share