【发布时间】:2014-11-04 11:29:22
【问题描述】:
您好,我有一个数组,其中包含从 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
}
【问题讨论】:
标签: swift duplicates uicollectionview cells