I\'m using the code below to delete a row in my tableview. First I delete the object from my array and then from the tableview using this code:
let i = IndexPath
I think you store rowNum
variable with your cell and it's set in cellForRow(at:)
method. If what I think is right then here's a thing.
UITableView
try to do at least work as possible. This means that after you delete a cell, UITableView
won't gonna call cellForRow(at:)
methods on its datasource again until you call reloadData()
or reloadRows(at:animation:)
methods.
So when you delete the first cell, rowNum
variable on other cells won't gonna be updated until you call reloadData()
as you tried and saw that's work.
My suggestion is don't keep rowNum
variable at a cell but ask UITableView
for the index path of any cell via indexPath(for:)
method on UITableView
instead.