delete row UITableView index issue

前端 未结 11 1737
遥遥无期
遥遥无期 2021-02-13 04:24

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         


        
11条回答
  •  后悔当初
    2021-02-13 04:36

    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.

提交回复
热议问题