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



当我尝试通过子类通过调用其方法访问父类单元格时,它崩溃了,因为只有collectionview的可见单元格在队列中,但cellForItemAtIndexPath不可见单元格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
}
}
}
}

这是父类的代码:

func mymethodforback(images:NSIndexPath , vc :PSUserSentPhotoDetailsVC) {
print( images.row)
print(PSMediaDetailVC.collection.visibleCells().count)
var cell :PSMediaCollectionViewCell = PSMediaDetailVC.collection.cellForItemAtIndexPath(images) as! PSMediaCollectionViewCell  
// here i m getting nil because cell for particular indexpath is not visible in parent class
var imageView:UIImageView = cell.imagevieww as UIImageView
PSMediaDetailVC.imageve = imageView
print("xcxcxcxc")
print( PSMediaDetailVC.imageve)
print(PSMediaDetailVC.collection)
print(self)
self.ysl_addTransitionDelegate(PSMediaDetailVC.collection)
self.navigationController(PSMediaDetailVC.nvc, animationControllerForOperation: UINavigationControllerOperation.Push, fromViewController: self, toViewController:vc )
// self.ysl_pushTransitionAnimationWithToViewControllerImagePointY(0, animationDuration: 0.3)        
}

UICollectionView中的单元格显示来自基础数据模型的信息,它们本身不存储信息。 因此,无需将当前不在屏幕上的单元格保留在内存中;可以通过在需要时调用cellForItemAtIndexPath轻松重新创建它们。 这使集合视图能够重用单元格对象并减少其内存占用量。

所有这一切的结果是,您无法通过在集合视图上调用cellForItemAtIndexPath来获取当前未显示的单元格。

最新更新