gpt4 book ai didi

ios - 无法删除 UITableView 中的行

转载 作者:行者123 更新时间:2023-11-30 13:59:51 25 4
gpt4 key购买 nike

我有 2 个数组,在删除行时需要从中删除数据,并且两个数组似乎都已删除。但是,当我滑动删除时,出现以下错误:

[2078:568325] *** Assertion failure in -[UITableView
_endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-3318.16.21/UITableView.m:1582 [2078:568325]
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid
number of rows in section 0. The number of rows contained in an
existing section after the update (2) must be equal to the number of
rows contained in that section before the update (2), plus or minus
the number of rows inserted or deleted from that section (0 inserted,
1 deleted) and plus or minus the number of rows moved into or out of
that section (0 moved in, 0 moved out).'

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {

if editingStyle == UITableViewCellEditingStyle.Delete {
audioPlayers[indexPath.row].stop()
audioFiles.removeAtIndex(indexPath.row)
audioPlayers.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
}

}

deleteRowsAtIndexPaths 似乎出错了。

最佳答案

在从数据模型中删除元素之前,尝试移动删除行的调用。像这样的事情:

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {

if editingStyle == UITableViewCellEditingStyle.Delete {
audioPlayers[indexPath.row].stop()
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
audioFiles.removeAtIndex(indexPath.row)
audioPlayers.removeAtIndex(indexPath.row)
}

}

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

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