When I use the following code
List {
ForEach(data.items, id: \.knowledgeInfo.mediaID) { item in
SelectableKnowledgeListItem(knowledgeData: item, baseID: data.knowledgeBaseID, isSelectionMode: $isSelectionMode, selectedItems: $selectedItems)
.KnowledgeListItemStyle()
}
// 添加底部加载更多
if !data.isEnd && !isRefreshing {
ProgressView()
.frame(maxWidth: .infinity, alignment: .center)
.onAppear {
self.isRefreshing = true
manager.getKnowledgeList(knowledgeBaseID: data.knowledgeBaseID, completion: {
self.isRefreshing = false
})
}
}
}
.animation(.interactiveSpring)
.scrollContentBackground(.hidden)
.environment(\.defaultMinListHeaderHeight, 7)
The number of Views rendered in the List remains unchanged after he adds an item to data.items (data is an ObservedObject, items is Published) at runtime.When I removed .animation(.interactiveSpring), it would be processed normally.And if I perform a delete operation after adding, it will cause a crash.
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections. The number of sections contained in the collection view after the update (11) must be equal to the number of sections contained in the collection view before the update (10), plus or minus the number of sections inserted or deleted (1 inserted, 1 deleted).