Hi,
I am unable to insert a new row into my table view, I get the following error while adding a new row:
reason: 'attempt to insert row 3 into section 0, but there are only 3 rows in section 0 after the update'
The following is my code:
source.append(data)
let indexPath = IndexPath(row: (source.count), section: 0)
tableView.insertRows(at: [indexPath], with: .automatic)The Above code deosn't work but it works if change the code to the following
let indexPath = IndexPath(row: (source.count), section: 0)
source.append(data)
tableView.insertRows(at: [indexPath], with: .automatic)So I really confused as the why the code works if generate a new IndexPath before appending the new data to the table's datasource.
The only thing i can come up with is that Index Path is initialized to a value at which there is no element in the array.
Also I debugged which functions are called when insertRows is executed, first the numberOfRows functions are calleld which in both cases return 3 and then the cellForRowAt if the code doesn't fail
Can anybody point me in the right direction as what I am missing in my knowleadge of TableView's