小编Loi*_*all的帖子

为什么滚动后消失我的UICollectionViewCells?

我使用的UICollectionView是自定义布局,但是在向下滚动和向上滚动后,单元格消失了,这是我遇到的问题。

请观看有关我的问题的视频演示

我已经进行了一些Google搜索,其他人也遇到了相关问题,并且我认识到这可能是由于单元重用造成的,但是我在其他地方找不到的答案都没有帮助我。

所以我的问题是:

  1. 为什么会这样呢?

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

有趣的是,一旦我提出UIViewController并关闭了它,该问题就不再发生。请观看实际操作中的视频

注意:此错误已经存在了一段时间(至少自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 …
Run Code Online (Sandbox Code Playgroud)

ios uicollectionview uicollectionviewcell uicollectionviewlayout swift

5
推荐指数
1
解决办法
981
查看次数

正确使用 ThreadPool 和 Generators

在 Python 2.7 中处理 CSV 文件时,我在使用ThreadPools 和 aGenerator时遇到问题。下面是一些示例代码,说明了我的观点:

from multiprocessing.dummy import Pool as ThreadPool
import time

def getNextBatch():
    # Reads lines from a huge CSV and yields them as required.
    for i in range(5):
        yield i;

def processBatch(batch):
    # This simulates a slow network request that happens.
    time.sleep(1);
    print "Processed Batch " + str(batch);

# We use 4 threads to attempt to aleviate the bottleneck caused by network I/O.
threadPool = ThreadPool(processes = 4)

batchGenerator = …
Run Code Online (Sandbox Code Playgroud)

python yield-keyword multiprocessing threadpool python-multiprocessing

4
推荐指数
1
解决办法
1363
查看次数