【发布时间】:2015-03-17 03:31:29
【问题描述】:
我正在下载一些图像并将它们插入到我的 UICollectionView 中
这些是我的班级成员
var myItems:[UIImage] = []
var myView: UICollectionView?
我有一个接收 img:UIImage 对象的定时器函数。我像这样将它插入到我的 UICollectionView 中
self.myItems.insert(img, atIndex: self.myItems.count)
var count:Int? = self.myView?.numberOfItemsInSection(0)
var index:NSIndexPath = NSIndexPath(forRow: count!, inSection: 0)
self.myView?.insertItemsAtIndexPaths([index])
我也有这个功能:
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.myItems.count;
}
还有这个:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as MyCollectionViewCell
cell.backgroundColor = UIColor.orangeColor()
cell.textLabel.text = "Text \(indexPath.row)"
cell.imageView.image = myItems[indexPath.row]
cell.backgroundView = UIImageView(image: UIImage(named: "cellbg"))
return cell
}
但是我的视图不会立即显示新图像。我必须点击空白屏幕,然后新单元格及其图像出现。如果有更多单元格适合视图,我也无法滚动视图。
如何刷新视图?我将单元格出列的方式有问题吗?
【问题讨论】:
标签: swift uicollectionview uicollectionviewcell