I am using a UICollectionView
with a custom layout, but I am having issues with cells disappearing after I scroll down and back up.
Please see a video demonstration of my issue.
I've done some Googling around and other people have related issues and I recognise that this is possibly due to cell reuse, but none of the answers I found elsewhere helped me.
So my questions are:
Why is this happening?
How do I stop this from happening?
Interestingly, once I present a UIViewController
and dismiss it, the issue no longer occurs. Please see the video of this in action.
NOTE: This bug has been here for a while (at least since iOS 10 and hasn't been fixed in iOS 11 beta 1 either).
Edit 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
Figured it out. So the line of code that was causing the problem was actually in viewDidAppear
and it was:
inputTextView?.becomeFirstResponder()
I have no idea why it caused the cell not to appear, but removing that line fixed the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With