Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 重新加载不调用cellForItemAt的数据_Ios_Swift_Xcode_Swift3 - Fatal编程技术网

Ios 重新加载不调用cellForItemAt的数据

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上实现了搜索栏,但是当调用
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)
进行比较,并在此基础上,重新加载所需的单元格,删除其余单元格或添加更多单元格。这样做的一个好处是,您还可以获得漂亮的过滤动画。

请显示搜索栏部分的代码并重新加载数据。