嗨我有一個陣列與100張圖片url從flickr採取。當我使用UICollectionView我顯示100個細胞中,只有8個細胞是在屏幕上,當我向下滾動才能看到未來8他們像以前一樣,當我執行Swift - UICollectionView重複(重複)單元格
func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell!
和println(「東西」)它在控制檯只寫8次的東西,但陣列的含量爲100
我用這個:
func collectionView(collectionView: UICollectionView?, numberOfItemsInSection section: Int) -> Int {
return self.photosUrls.count
}
它使100個細胞,但細胞總是重複...任何人誰知道如何擊敗斯威夫特在XCode GM種子的新版本中?
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
}
我添加了代碼。看到它,謝謝:) – 2014-09-11 08:01:22