如何在目标c中访问子类中父类集合视图的不可见单元格

时间:2016-12-14 08:44:30

标签: ios swift uicollectionview

当我尝试通过调用其方法通过子类访问父类单元格时,它会崩溃,因为只有collectionview的可见单元格在队列中,但cellForItemAtIndexPath对于不可见单元格是{{1} }

以下是我的子类的代码:

nil

这是父类的代码:

 func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
    print(self.collectionView.visibleCells())

    for cell in self.collectionView.visibleCells() {
        let collectionViewCell = cell as! PSMediaCell
        let indexPath:NSIndexPath = self.collectionView.indexPathForCell(collectionViewCell)!
        let  imageObj:NSMutableDictionary = imageArr.objectAtIndex(indexPath.item) as! NSMutableDictionary

        // this is calling parent class method
        mediavc.mymethodforback(indexPath, vc: self)

        if imageObj.objectForKey("image_url")?.rangeOfString("mov").length > 0 {
        } else {
            var imageView:UIImageView = collectionViewCell.contentView.viewWithTag(122) as! UIImageView
             imagev = imageView
            let indicatorView:UIActivityIndicatorView = collectionViewCell.contentView.viewWithTag(233) as! UIActivityIndicatorView
            var videoIcon:UIImageView = cell.contentView.viewWithTag(133) as! UIImageView
            var imageOverlay:UIImageView = collectionViewCell.contentView.viewWithTag(234) as! UIImageView
            //var videoIcon:UIImageView = collectionViewCell.contentView.viewWithTag(133) as! UIImageView
            var downloadingFilePath = NSTemporaryDirectory().stringByAppendingPathComponent(imageObj.objectForKey("image_url") as! String)
            let imageN = UIImage(contentsOfFile:downloadingFilePath as String )
            if imageN == nil {
                var downloadRequest = AWSS3TransferManagerDownloadRequest()
                var downloadingFilePath1 = NSTemporaryDirectory().stringByAppendingPathComponent(imageObj.objectForKey("image_url") as! String)
                let downloadingFileURL = NSURL(fileURLWithPath: downloadingFilePath1)
                downloadRequest.bucket = "photosharebucket1"
                downloadRequest.key = imageObj.objectForKey("image_url") as! String
                downloadRequest.downloadingFileURL = downloadingFileURL
                self.download(downloadRequest, ImageObj:imageObj)
                indicatorView.hidden = false
                imageOverlay.hidden  = false
            } else {
                imageView.image = imageN
                indicatorView.hidden = true
                imageOverlay.hidden  = true
                videoIcon.hidden  = true
            }
         }
     }
 }

1 个答案:

答案 0 :(得分:1)

cellForItemAtIndexPath中的单元格显示来自基础数据模型的信息,它们不会以自己的方式存储信息。结果,不需要当前在屏幕上的单元格保存在存储器中;在需要之前调用cellForItemAtIndexPath可以轻松地重新创建它们。这使集合视图能够重用单元对象并减少其内存占用。

所有这一切的结果是,您无法通过在集合视图上调用<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> 来获取当前未显示的单元格。