我目前设置了一个集合视图,以在其视图中显示动态数量的对象。每个单元格显示来自相应对象的图像。当点击一个单元格时,它会触发一个segue到层次结构中的下一个视图。单元格的相应对象被传递到下一个视图但是,我注意到当我返回带有集合的视图时,单元格的排序已经改变,现在,当我点击一个来获得下一个视图时,它的属性来自对象其他细胞。
以下是我的UICollectionView方法:
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return objectsCount
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Chow Object Reuse ID", forIndexPath: indexPath) as UICollectionViewCell
cell.backgroundColor = UIColor.whiteColor()
var imageView:UIImageView = UIImageView()
imageView.frame = CGRect(x: 0, y: 0, width: 90, height: 90)
//Since loading of images is a time-intensive task, all the thumbnails
//may have not been fetched yet.
if (imageThumbsArray.count == objectsCount) { //Eventually, a more elegant fix will be needed.
imageView.image = imageThumbsArray[indexPath.row]
}
cell.addSubview(imageView)
return cell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
self.objectToBePassed = self.chowObjectsArray[indexPath.row] as PFObject
self.performSegueWithIdentifier("Show Chow Details", sender: self)
}
我也打电话给self.PastObjectsCollection.reloadData()
为什么要重新排序和混合细胞呢?
谢谢, 亚洲时报Siddharth