作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我尝试通过子类调用其方法访问父类单元格时它崩溃了,因为只有 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
可以很容易地重新创建它们。这使 Collection View 能够重用单元格对象并减少其内存占用。
所有这一切的结果是,您无法通过在 Collection View 上调用 cellForItemAtIndexPath
来获取当前未显示的单元格。
关于ios - 如何在 objective-c 中访问子类中父类 Collection View 的不可见单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41138180/
我是一名优秀的程序员,十分优秀!