UICollectionView选中的单元格会变成白色吗?

时间:2015-09-25 06:27:47

标签: ios swift uicollectionview uicollectionviewcell

编程逻辑如下。 在后台主题中加载媒体中的媒体, 每当medias计数%30 == 0时,它将在主线程中重新加载collectionView。

这是我的代码

backgroundThread函数

func backgroundThread(delay: Double = 0.0, background: (() -> Void)? = nil, completion: (() -> Void)? = nil) {
        dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.value), 0)) {
            if(background != nil){ background!(); }

            let popTime = dispatch_time(DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC)))
            dispatch_after(popTime, dispatch_get_main_queue()) {
                if(completion != nil){ completion!(); }
            }
        }
    }

loadMedia函数

func loadMedias() {
        Log.shareInstance.p("PTVideo - loadMedias begin", caller: self)
        assetLibrary.enumerateGroupsWithTypes(ALAssetsGroupSavedPhotos, usingBlock: { (grp: ALAssetsGroup!, groupBool: UnsafeMutablePointer<ObjCBool>) -> Void in
            // do something here
            if ALAssetsFilter.allVideos() != nil && grp != nil {
                if grp != nil {
                    grp.enumerateAssetsUsingBlock({ (asset, index, assetBool) -> Void in

                        if asset != nil  {
                                self.medias.append(asset!)
                            if(count(self.medias) % 30 == 0){
                                dispatch_async(dispatch_get_main_queue(), { () -> Void in
                                    self.mediaCollection.reloadData()
                                })
                            }

                        }

                    })
                }
            }
            }) { (error) -> Void in
                // Handle error
                println("error in fetching assets")
        }

    }

以这种方式在viewDidLoad函数中调用它们

self.backgroundThread(delay: 0, background: { () -> Void in
            self.loadMedias()
        }, completion: nil)

一切看起来都很完美,但当我点击collectionView的单元格时,细胞会变成白色,如下所示...... white cell...

0 个答案:

没有答案