Ios 重新加载不调用cellForItemAt的数据
我随后在collectionview上实现了搜索栏,但是当调用Ios 重新加载不调用cellForItemAt的数据,ios,swift,xcode,swift3,Ios,Swift,Xcode,Swift3,我随后在collectionview上实现了搜索栏,但是当调用collectionview?.reloadData()时,会显示下面的屏幕,我必须向下滚动以查找过滤后的单元格。 我的数据源代码 override func numberOfSections(in collectionView: UICollectionView) -> Int { return 2 } override func collectionView(_ collectionView: UICollecti
collectionview?.reloadData()
时,会显示下面的屏幕,我必须向下滚动以查找过滤后的单元格。
我的数据源代码
override func numberOfSections(in collectionView: UICollectionView) -> Int {
return 2
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return section == 0 ? 0 : count // this got called after reloadData
}
override func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(...)
// this function did not get called after reloadData
}
确保在重新加载collectionview时,它会显示一些内容。Count有一些值如果数据源有0值,那么也不会调用cellForItem 发现问题…我将搜索栏高度设置为
collectionView.contentSize
,在重新加载数据后,由于某种原因,搜索栏高度从50变为2600?过滤数据源数组后,您可以将count
与collectionView.numberOfItemsInSection(1)
进行比较,并在此基础上,重新加载所需的单元格,删除其余单元格或添加更多单元格。这样做的一个好处是,您还可以获得漂亮的过滤动画。请显示搜索栏部分的代码并重新加载数据。