Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableView节删除问题_Ios_Swift_Uitableview - Fatal编程技术网

Ios UITableView节删除问题

Ios UITableView节删除问题,ios,swift,uitableview,Ios,Swift,Uitableview,我有2个部分和1/59行。 我删除了行(因此在0部分中我得到了0行),并得到了此崩溃(也是-[UITableView deleteRowsAtIndexPaths:withRowAnimation:works处的断点)。无法获取此1(已删除)是如何计算的 Invalid update: invalid number of sections. The number of sections contained in the table view after the update (2) must

我有
2个部分
1
/
59
行。 我删除了行(因此在0部分中我得到了0行),并得到了此崩溃(也是
-[UITableView deleteRowsAtIndexPaths:withRowAnimation:
works处的断点)。无法获取此1(已删除)是如何计算的

Invalid update: invalid number of sections.  The number of sections contained in the table view after the update (2) must be equal to the number of sections contained in the table view before the update (2), plus or minus the number of sections inserted or deleted (0 inserted, 1 deleted)
我收到这条消息,但根本没有删除节,位于
-[UITableView deleteSections:withRowAnimation:][/code>的断点不起作用

有什么想法/建议吗


谢谢

我想发生了什么,但我不确定,因为我没有看到您的代码。 我将尝试向您解释,当您要删除表中的行或节时,要遵循的过程是什么

我猜想你们有一个带行的数组,还有一个带节的数组

1-必须从行数组中删除行:

arrayRows.removeAtIndex(indexRow)
2-必须从节数组中删除节(如有必要):

arraySections.removeAtIntex(indexSection)
3-现在是使用下一个代码从表中删除该行的时刻:

tableView.beginUpdates()
tableView.deleteRowsAtIndexPaths(indexRow, withRowAnimation: UITableViewRowAnimation.Fade)
//If you want delete sections, firstly you must delete all rows of this section
tableView.deleteSections(indexSection, withRowAnimation: UITableViewRowAnimation.Fade)
tableView.endUpdates()

//After this, you must reload data of table
tableView.reloadData()
PD:确保方法numberOfRowsInSection和numberOfSectionsInTableView从行和节的数组中获取数据。像这样:

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return arraySections.count
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    //Return array of rows of section
    return arrayRows.count
}
我希望有帮助


如果您有疑问,请告诉我,我会尝试以其他方式帮助您。

显示更多您尝试过的代码。检查此链接BeginUpdate/EndUpdate之间没有重新加载数据的调用删除后,您是否正在更新节数?