ros*_*ter 2 uicollectionview uicollectionviewcell swift
我正在下载一些图像并将它们插入到我的 UICollectionView 中
这些是我的班级成员
var myItems:[UIImage] = []
var myView: UICollectionView?
Run Code Online (Sandbox Code Playgroud)
我有一个接收 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])
Run Code Online (Sandbox Code Playgroud)
我也有这个功能:
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.myItems.count;
}
Run Code Online (Sandbox Code Playgroud)
和这个:
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
}
Run Code Online (Sandbox Code Playgroud)
但是我的视图不会立即显示新图像。我必须点击空白屏幕,然后新单元格及其图像就会出现。此外,如果视图中有更多单元格,我也无法滚动视图。
如何刷新视图?我使单元出队的方式有问题吗?