我正在使用带有自定义布局的UICollectionView
,但在向下滚动并备份后,单元格消失。为什么我的UICollectionViewCells在滚动后消失?
请参阅我的问题的video demonstration。
我已经做了一些谷歌搜索和其他人有相关的问题,我认识到这可能是由于细胞再利用,但没有在其他地方找到的答案帮助我。
所以我的问题是:
这究竟是为什么?
如何防止这种情况发生?
有趣的是,当我提出一个UIViewController
和关闭它,问题不再出现。请参阅此处的video。
注意:这个bug在这里已经有一段时间了(至少从iOS 10开始并且还没有在iOS 11 beta 1中修复过)。
编辑1
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
switch (indexPath as NSIndexPath).row {
case 0:
// Speak Logo Cell
let speakLogoCell = collectionView.dequeueReusableCell(withReuseIdentifier: "SpeakLogoCell", for: indexPath) as! SpeakLogoCell
recordButton = speakLogoCell.recordButton
return speakLogoCell
case 1:
// Text Input Cell
let inputCell = collectionView.dequeueReusableCell(withReuseIdentifier: "InputCell", for: indexPath) as! InputCell
inputCell.inputTextView.delegate = self
inputTextView = inputCell.inputTextView
// Only restore input if launching and required.
if currentlyLaunching && UserDefaultsHelper.loadShouldRestoreInput() {
inputTextView!.text = UserDefaultsHelper.loadInput() ?? ""
}
return inputCell
case 2:... // Continues for all the other cells
1. iOS删除该单元格以节省资源,因为它没有显示,并且您没有正确重新初始化它。 2.正确重新初始化单元格。 (你认为我们是魔术师,真的可以帮助你没有*相关的*代码?) – idmean
感谢您的回复和建议发布一些相关的代码。我要编辑我的问题以包含cellForItem方法的适当部分。请让我知道你是否想要其他东西。 –
什么是inputTextView?它存储在哪里? –