我有一个带图片的CollectionView应该从网络加载。
URL链接在字符串数组中,而collectionView单元格中是imageView。
我找到了这段代码:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! ViewCell
var url = NSURL(string: "\(array[indexPath.row])")
var err: NSError?
var imageData: NSData = NSData(contentsOfURL: url!, options: NSDataReadingOptions.DataReadingMappedIfSafe, error: &err)!
var bgImage = UIImage(data:imageData)
cell.imgView.image = bgImage
// cell.imgView.image = UIImage(named: array[indexPath.row])
cell.load.hidden = false
cell.load.startAnimating()
cell.load.hidesWhenStopped = true
if cell.imgView.image == nil {
cell.load.startAnimating()
}else{
cell.load.stopAnimating()
}
return cell
}
问题出现在启动时。 应用程序已加载,我在我的MainVC(带有collectionView)中看到一些println的注释,但在iPad上却冻结了启动屏幕。
我试着将入口点放到另一个视图中,它可以正常工作,直到我segue到MainVC,一切都冻结,没有响应任何触摸。
可能出了什么问题?
谢谢任何帮助!