【问题标题】:UITableview: Attempt to delete and reload the same index path (<NSIndexPath: 0xa8d9c10c8af4b9b4> {length = 2, path = 0 - 0})UITableview:尝试删除并重新加载相同的索引路径(<NSIndexPath: 0xa8d9c10c8af4b9b4> {length = 2, path = 0 - 0})
【发布时间】:2021-10-30 23:36:16
【问题描述】:

我是 iOS 编码的新手。我试图删除 UITableview 中的唯一行并收到以下错误“尝试删除并重新加载相同的索引路径 ( {length = 2, path = 0 - 0})”。我寻找了类似的线程 - 这似乎是几年前发现的错误,但是,我似乎没有看到最近报告的问题,所以我想知道我是否做错了什么。非常感谢您的帮助!

  func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
      
            if editingStyle == .delete {
             
                    let len = displayList.count
                    displayList.remove(at: indexPath.row)
              
                  //  self.totTableView.beginUpdates()
                    if displayTotList.count == len - 1{

                        totTableView.deleteRows(at: [indexPath], with: .automatic)
                        totTableView.reloadData()
                        
                    }
             
                   // self.totTableView.reloadRows(at: [indexPath as IndexPath], with: UITableView.RowAnimation.automatic)
                //    self.totTableView.endUpdates()
                        
           }
 }

【问题讨论】:

    标签: ios swift uitableview tableview


    【解决方案1】:

    如果 displayTotList 是您的数据源,您可以在从 displayList 中删除项目后重新加载数据,而无需删除行。 或者如果你想要一个删除动画,你可以在不重新加载数据的情况下删除行

    【讨论】:

    • 非常感谢您的帮助!这对我有用! :)
    猜你喜欢
    • 2016-01-12
    • 2015-06-02
    • 2015-10-01
    • 2021-04-12
    • 2021-12-14
    • 2012-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多