【发布时间】:2019-02-17 07:40:46
【问题描述】:
我有一个数组,我需要在单击“关闭”时添加和删除单元格数据,这是标题部分中的 UIButton
我正在循环数组并获取行,对于部分我使用了静态数据并在 indexPaths 中添加,然后在
tblSideNav.deleteRows(at: indexPaths, with: .fade)
如上一行 start execution app got crash
var menusArray = [sideNavStruct(isOpend: true, menuImg: "user", menuTitle: "Profile", subMenu: ["My Profile", "Distributor Profile"]), sideNavStruct(isOpend: true, menuImg: "user", menuTitle: "Reports", subMenu: ["Stock Report", "NFR Report", "RTD”])]
@objc func handleOpenCloseCell() {
let section = 0
var indexPaths = [IndexPath]()
for row in menusArray[section].subMenu.indices {
let indexPath = IndexPath(row: row, section: section)
indexPaths.append(indexPath)
}
print(indexPaths.count)
print(menusArray[section].subMenu[0])
menusArray[section].subMenu[0].removeAll()
tblSideNav.deleteRows(at: indexPaths, with: .fade)
}
我的应用在tblSideNav.deleteRows(at: indexPaths, with: .fade) 上崩溃了:
无效更新:第 0 节中的行数无效。 更新 (7) 后包含在现有节中的行必须是 等于该节之前包含的行数 update (2),加或减插入或删除的行数 该部分(0 插入,2 删除)和加或减的数量 移入或移出该部分的行(0 移入,0 移出)。
我找不到问题
【问题讨论】:
-
崩溃说明了什么?
-
Labwa @AhmadF ...
-
@AhmadF 原因:'无效更新:第 0 节中的行数无效。更新后现有节中包含的行数 (7) 必须等于其中包含的行数更新前的节 (2),加上或减去从该节插入或删除的行数(0 插入,2 删除),加上或减去移入或移出该节的行数(0 移入,0 移动出)。'
标签: ios swift uitableview uitableviewsectionheader