你好,我有一个数组,其中包含从 flickr 获取的 100 张图片 url。当我使用 UICollectionView 时,我显示 100 个单元格,屏幕上只有 8 个单元格,当我向下滚动查看下一个 8 个单元格时,它们与前一个单元格相同,并且当我执行时
func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell!
和 println("something") 它在控制台中只写入 8 次,但数组的内容是 100
我用这个:
func collectionView(collectionView: UICollectionView?, numberOfItemsInSection section: Int) -> Int {
return self.photosUrls.count
}
它制作了 100 个单元,但单元总是重复...有人知道如何在新版本的 XCode GM 种子中击败 Swift 吗?
func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell! {
let cell: ImageCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as ImageCell
let imgUrl = photosUrls[indexPath!.row]
let api_url = NSURL.URLWithString(imgUrl)
let URLReq = NSURLRequest(URL: api_url)
let NSOpQ:NSOperationQueue = NSOperationQueue()
NSURLConnection.sendAsynchronousRequest(URLReq, queue: NSOpQ, completionHandler:{ (response: NSURLResponse!, data: NSData!, error: NSError!) -> Void in
if(error == nil){
cell.theWPImage!.image = UIImage(data: data)
}
})
return cell
}