【发布时间】:2016-01-01 04:58:27
【问题描述】:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
MBProgressHUD.hideHUDForView(self.view, animated: true)
var url : String
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! celll
let imagess : UIImageView = cell.image
url = self.imageArray.objectAtIndex(indexPath.row).valueForKey("photo-url-500") as! String
[imagess.sd_setImageWithURL(NSURL(string: url), placeholderImage: nil)]
return cell
}
func collectionView(collectionView: UICollectionView!, layout collectionViewLayout: UICollectionViewLayout!, sizeForItemAtIndexPath indexPath: NSIndexPath!) -> CGSize
{
let cgsize : CGSize = CGSizeMake(CGFloat(A_size_width.objectAtIndex(indexPath.row) as! NSNumber), CGFloat(A_size_height.objectAtIndex(indexPath.row) as! NSNumber))
return cgsize
}
func scrollViewDidEndDecelerating(scrollView: UIScrollView)
{
let bottomFloat : CGFloat = scrollView.contentOffset.y + scrollView.frame.height
if bottomFloat >= scrollView.contentSize.height
{
let str = (json.valueForKey("posts-total") as! NSNumber)
let value:Int = Int(str)
if (StartNumber < value)
{
reachedEnd = false;
self.jsonParsingFromURL(StartNumber)
StartNumber = StartNumber + 30;
}
else
{
reachedEnd = true;
[self.IMG_collection .reloadSections(NSIndexSet(index: 0))]
}
}
}
func fileheight_width()
{
let qualityOfServiceClass = QOS_CLASS_BACKGROUND
let backgroundQueue = dispatch_get_global_queue(qualityOfServiceClass, 0)
dispatch_async(backgroundQueue, {
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if self.StartNumber == self.imageArray.count
{
for var i = 0 ; i < self.imageArray.count ; i++
{
let str :String = self.imageArray.objectAtIndex(i).valueForKey("photo-url-500") as! String
let Imagesource : CGImageSourceRef = CGImageSourceCreateWithURL(NSURL(string: str)!, nil)!
let pixelHeight = kCGImagePropertyPixelHeight as String
let pixelWidth = kCGImagePropertyPixelWidth as String
let imgProperty = CGImageSourceCopyPropertiesAtIndex(Imagesource, 0, nil) as NSDictionary!
let height = imgProperty[pixelHeight] as! CGFloat!
let width = imgProperty[pixelWidth] as! CGFloat!
self.A_size_width.addObject(width)
self.A_size_height.addObject(height)
}
}
else
{
for var i = 0 ; i < self.imageArray.count ; i++
{
let str :String = self.imageArray.objectAtIndex(i).valueForKey("photo-url-500") as! String
let Imagesource : CGImageSourceRef = CGImageSourceCreateWithURL(NSURL(string: str)!, nil)!
let pixelHeight = kCGImagePropertyPixelHeight as String
let pixelWidth = kCGImagePropertyPixelWidth as String
let imgProperty = CGImageSourceCopyPropertiesAtIndex(Imagesource, 0, nil) as NSDictionary!
let height = imgProperty[pixelHeight] as! CGFloat!
let width = imgProperty[pixelWidth] as! CGFloat!
self.A_size_width.addObject(width)
self.A_size_height.addObject(height)
}
}
})
[self.IMG_collection.reloadData()]
})
}
现在图像来自 Json 并存储在 imageArray 和 JSON 中,但是当我向下滚动集合视图时,然后在应用程序冻结 2-3 分钟后调用此方法func scrollViewDidEndDecelerating(scrollView: UIScrollView)。请给我一些解决方案。
并提前感谢您。
【问题讨论】:
标签: ios json swift uiscrollview uicollectionview