gpt4 book ai didi

ios - 无法删除索引路径中的行

转载 作者:搜寻专家 更新时间:2023-11-01 07:06:53 24 4
gpt4 key购买 nike

我有一些 tableview 单元格,上面有一些数据,单元格上有一个十字按钮(在右上角),单击它应该删除单元格。这就是我试图删除的方式......

extension sellTableViewController: imageDelegate {
func delete(cell: sellTableViewCell) {
if let indexPath = tableview?.indexPath(for: cell) {
//1.Delete photo from datasource
arrProduct?.remove(at: indexPath.row)
print(self.appDelegate.commonArrForselectedItems)

tableview.deleteRows(at: [indexPath], with: .fade)

}
}
}

但是当我单击十字按钮时,我收到一条错误消息,提示 更新 (1) 之后 TableView 中包含的部分数量必须等于更新 (1) 之前 TableView 中包含的部分数量更新 (2),加上或减去插入或删除的节数(插入 0 个,删除 0 个)。'

我的 TableView numberOfSectionsnumberOfRowsInSection 给出如下...

    func numberOfSections(in tableView: UITableView) -> Int {
return (arrProduct?.count)!

}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

let product = arrProduct![section]

return product.images.count
}

希望有人能帮忙...

最佳答案

您正在从 indexPath.row 的数组中删除项目,但您的数组包含部分而不是行

一行错误替换

        arrProduct?.remove(at: indexPath.row)

        arrProduct?.remove(at: indexPath.section)

希望对你有帮助

编辑

我认为你正在从数组中删除图像

arrProduct![indexPath.section].images.remove(at: indexPath.row)

关于ios - 无法删除索引路径中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47456004/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com