【发布时间】:2016-02-15 07:36:08
【问题描述】:
我有一个要在 UITableView 中显示的数据集。我想作为第 0 部分插入的所有新数据集。通常,我会得到很多集,然后我想一次将它们推送到顶部。这看起来像
tableView.beginUpdates()
repeat {
data.append(dataProvider.nextDataSet())
tableView.insertSections(NSIndexSet(index:0), withRowAnimation: .Automatic)
} while dataProvider.hasMoreData
tableView.endUpdates()
虽然我的 data 数组与我想要的完全一样,但我的应用程序崩溃时会说:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections. The number of sections contained in the table view after the update (5) must be equal to the number of sections contained in the table view before the update (0), plus or minus the number of sections inserted or deleted (2 inserted, 0 deleted).'
我制作了a little sample project on GitHub,通过这样做来重现这个问题
numSections += 1
tableView.insertSections(NSIndexSet(index:0), withRowAnimation: .Automatic)
五次 (link) 其中 numSections 是节数,每个节的行数始终为 3。它再次说我只插入了 2 个部分,而实际上我确实插入了 5 个。
我在这里误解了什么?为什么 tableView 认为我只给了它 2 个新部分?当然,如果我只给它2个部分,它认为我只给它1个。:-I
【问题讨论】:
标签: ios swift uitableview sections