gpt4 book ai didi

ios - 为什么我的 UICollectionView 单元格在滚动后消失了?

转载 作者:搜寻专家 更新时间:2023-10-31 19:36:51 25 4
gpt4 key购买 nike

我正在使用具有自定义布局的 UICollectionView,但我遇到了在向下滚动并返回后单元格消失的问题。

请看video demonstration我的问题。

我进行了一些谷歌搜索,其他人也有相关问题,我认识到这可能是由于单元重复使用,但我在其他地方找到的答案都没有帮助我。

所以我的问题是:

  1. 为什么会这样?

  2. 如何阻止这种情况发生?

有趣的是,一旦我展示了一个 UIViewController 并将其关闭,问题就不再出现了。请参阅video这在行动中。

注意:这个错误已经存在一段时间了(至少从 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

最佳答案

想通了。所以导致问题的代码行实际上在 viewDidAppear 中,它是:

inputTextView?.becomeFirstResponder()

我不知道为什么它导致单元格不出现,但删除该行解决了问题。

关于ios - 为什么我的 UICollectionView 单元格在滚动后消失了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44637831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com