[英]Invalid number of rows in section Swift 3
我有一个包含Card()类的数组字典,我有一个调用函数的按钮,该函数移动一个数组
static var DeliveryStatusArray =
[
"claimable": [Card](),
"onTime": [Card](),
"future": [Card](),
"claimDone": [Card](),
"tooOld": [Card](),
]
我移动卡的功能是
static func moveCard(card:Card) -> Void {
var pos:Int = -1
var index:Int = 0
while(index < (DashboardManager.DeliveryStatusArray["claimable"]?.count)!)
{
if (DashboardManager.DeliveryStatusArray["claimable"]?[index].idCard == card.idCard)
{
pos = index
}
index += 1
}
if (pos > -1)
{
let card:Card = (DashboardManager.DeliveryStatusArray["claimable"]?[pos])!
DashboardManager.DeliveryStatusArray["claimable"]?.remove(at: pos)
DashboardManager.DeliveryStatusArray["claimDone"]?.append(card)
}
}
完成后,我会在视图中发布通知以调用此函数
func notificationFinish(notification:Notification) -> Void{
let sectionClaimable:Int = (api.dictionary["delivery"]?.index(of: "claimable"))! // Is 1
let sectionClaiDone: Int = (api.dictionary["delivery"]?.index(of: "claimDone"))! // Is 4
tableView.reloadSections(IndexSet(integer: sectionClaimable), with: .top)
tableView.reloadSections(IndexSet(integer: sectionClaimDone), with: .top)
return
}
在第一个循环中,我在* DeliveryStatusArray [“ claimDone] *中得到了2张卡片,在调用moveCard()之后,我得到了3张卡片
我得到了错误
***由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无效更新:第4节中的行数无效。更新(3)后现有节中包含的行数必须等于行数更新(2)之前包含在该部分中的内容,加上或减去从该部分插入或删除的行数(已插入0,已删除0),以及加上或减去移入或移出该部分的行数(移入0) ,0移出)。
重新加载数据时我无法获得更多物品?
如果我理解正确,那么您的代码比需要的复杂得多。
// Get the index of card in claimable with matching idCard
guard let index = deliveryStatusArray["claimable"]?.index(where: {$0.idCard == card.idCard }) else { return }
// Remove the card at that index
let card = deliveryStatusArray["claimable"]?.remove(at: index)
// Append the card
deliveryStatusArray["claimDone"]?.append(card)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.